summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Gavalas <njg@fb.com>2018-09-10 18:55:49 -0400
committerNick Gavalas <njg@fb.com>2018-09-12 15:47:57 -0400
commitb4513fc4b0381bdff00c52e294e6da6c7f27aa19 (patch)
tree6100777ec89473e95393894e6d375282b3979618
parent78af99c2566ef8fed443ce253e0de9323b9e5043 (diff)
downloadale-b4513fc4b0381bdff00c52e294e6da6c7f27aa19.zip
fix non-. prefix triggers overfiltering results
-rw-r--r--autoload/ale/completion.vim8
-rw-r--r--test/completion/test_completion_filtering.vader26
2 files changed, 24 insertions, 10 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index e96774c3..2556d50c 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -98,14 +98,15 @@ function! ale#completion#GetTriggerCharacter(filetype, prefix) abort
return ''
endfunction
-function! ale#completion#Filter(buffer, suggestions, prefix) abort
+function! ale#completion#Filter(buffer, filetype, suggestions, prefix) abort
let l:excluded_words = ale#Var(a:buffer, 'completion_excluded_words')
+ let l:triggers = s:GetFiletypeValue(s:trigger_character_map, a:filetype)
" For completing...
" foo.
" ^
" We need to include all of the given suggestions.
- if a:prefix is# '.'
+ if index(l:triggers, a:prefix) >= 0
let l:filtered_suggestions = a:suggestions
else
let l:filtered_suggestions = []
@@ -369,7 +370,7 @@ function! ale#completion#ParseLSPCompletions(response) abort
endfor
if has_key(l:info, 'prefix')
- return ale#completion#Filter(l:buffer, l:results, l:info.prefix)
+ return ale#completion#Filter(l:buffer, &filetype, l:results, l:info.prefix)
endif
return l:results
@@ -390,6 +391,7 @@ function! ale#completion#HandleTSServerResponse(conn_id, response) abort
if l:command is# 'completions'
let l:names = ale#completion#Filter(
\ l:buffer,
+ \ &filetype,
\ ale#completion#ParseTSServerCompletions(a:response),
\ b:ale_completion_info.prefix,
\)[: g:ale_completion_max_suggestions - 1]
diff --git a/test/completion/test_completion_filtering.vader b/test/completion/test_completion_filtering.vader
index ae91a952..ffb313ef 100644
--- a/test/completion/test_completion_filtering.vader
+++ b/test/completion/test_completion_filtering.vader
@@ -12,16 +12,17 @@ After:
Execute(Prefix filtering should work for Lists of strings):
AssertEqual
\ ['FooBar', 'foo'],
- \ ale#completion#Filter(bufnr(''), ['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
+ \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
AssertEqual
\ ['FooBar', 'FongBar', 'baz', 'foo'],
- \ ale#completion#Filter(bufnr(''), ['FooBar', 'FongBar', 'baz', 'foo'], '.')
+ \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], '.')
Execute(Prefix filtering should work for completion items):
AssertEqual
\ [{'word': 'FooBar'}, {'word': 'foo'}],
\ ale#completion#Filter(
\ bufnr(''),
+ \ '',
\ [
\ {'word': 'FooBar'},
\ {'word': 'FongBar'},
@@ -40,6 +41,7 @@ Execute(Prefix filtering should work for completion items):
\ ],
\ ale#completion#Filter(
\ bufnr(''),
+ \ '',
\ [
\ {'word': 'FooBar'},
\ {'word': 'FongBar'},
@@ -56,6 +58,7 @@ Execute(Excluding words from completion results should work):
\ [{'word': 'Italian'}],
\ ale#completion#Filter(
\ bufnr(''),
+ \ '',
\ [
\ {'word': 'Italian'},
\ {'word': 'it'},
@@ -67,6 +70,7 @@ Execute(Excluding words from completion results should work):
\ [{'word': 'Deutsch'}],
\ ale#completion#Filter(
\ bufnr(''),
+ \ '',
\ [
\ {'word': 'describe'},
\ {'word': 'Deutsch'},
@@ -78,6 +82,7 @@ Execute(Excluding words from completion results should work):
\ [{'word': 'Deutsch'}],
\ ale#completion#Filter(
\ bufnr(''),
+ \ '',
\ [
\ {'word': 'describe'},
\ {'word': 'Deutsch'},
@@ -90,19 +95,26 @@ Execute(Excluding words from completion results should work with lists of String
AssertEqual
\ ['Italian'],
- \ ale#completion#Filter(bufnr(''), ['Italian', 'it'], 'it')
+ \ ale#completion#Filter(bufnr(''), '', ['Italian', 'it'], 'it')
AssertEqual
\ ['Deutsch'],
- \ ale#completion#Filter(bufnr(''), ['describe', 'Deutsch'], 'de')
+ \ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], 'de')
AssertEqual
\ ['Deutsch'],
- \ ale#completion#Filter(bufnr(''), ['describe', 'Deutsch'], '.')
+ \ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], '.')
Execute(Filtering shouldn't modify the original list):
let b:ale_completion_excluded_words = ['it', 'describe']
let b:suggestions = [{'word': 'describe'}]
- AssertEqual [], ale#completion#Filter(bufnr(''), b:suggestions, '.')
+ AssertEqual [], ale#completion#Filter(bufnr(''), '', b:suggestions, '.')
AssertEqual b:suggestions, [{'word': 'describe'}]
- AssertEqual [], ale#completion#Filter(bufnr(''), b:suggestions, 'de')
+ AssertEqual [], ale#completion#Filter(bufnr(''), '', b:suggestions, 'de')
AssertEqual b:suggestions, [{'word': 'describe'}]
+
+Execute(Filtering should respect filetype triggers):
+ let b:suggestions = [{'word': 'describe'}]
+
+ AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), '', b:suggestions, '.')
+ AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), 'rust', b:suggestions, '.')
+ AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), 'rust', b:suggestions, '::')