mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-21 19:51:17 +08:00
fix non-. prefix triggers overfiltering results
This commit is contained in:
@@ -98,14 +98,15 @@ function! ale#completion#GetTriggerCharacter(filetype, prefix) abort
|
|||||||
return ''
|
return ''
|
||||||
endfunction
|
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:excluded_words = ale#Var(a:buffer, 'completion_excluded_words')
|
||||||
|
let l:triggers = s:GetFiletypeValue(s:trigger_character_map, a:filetype)
|
||||||
|
|
||||||
" For completing...
|
" For completing...
|
||||||
" foo.
|
" foo.
|
||||||
" ^
|
" ^
|
||||||
" We need to include all of the given suggestions.
|
" 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
|
let l:filtered_suggestions = a:suggestions
|
||||||
else
|
else
|
||||||
let l:filtered_suggestions = []
|
let l:filtered_suggestions = []
|
||||||
@@ -369,7 +370,7 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
if has_key(l:info, 'prefix')
|
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
|
endif
|
||||||
|
|
||||||
return l:results
|
return l:results
|
||||||
@@ -390,6 +391,7 @@ function! ale#completion#HandleTSServerResponse(conn_id, response) abort
|
|||||||
if l:command is# 'completions'
|
if l:command is# 'completions'
|
||||||
let l:names = ale#completion#Filter(
|
let l:names = ale#completion#Filter(
|
||||||
\ l:buffer,
|
\ l:buffer,
|
||||||
|
\ &filetype,
|
||||||
\ ale#completion#ParseTSServerCompletions(a:response),
|
\ ale#completion#ParseTSServerCompletions(a:response),
|
||||||
\ b:ale_completion_info.prefix,
|
\ b:ale_completion_info.prefix,
|
||||||
\)[: g:ale_completion_max_suggestions - 1]
|
\)[: g:ale_completion_max_suggestions - 1]
|
||||||
|
|||||||
@@ -12,16 +12,17 @@ After:
|
|||||||
Execute(Prefix filtering should work for Lists of strings):
|
Execute(Prefix filtering should work for Lists of strings):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['FooBar', 'foo'],
|
\ ['FooBar', 'foo'],
|
||||||
\ ale#completion#Filter(bufnr(''), ['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
|
\ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['FooBar', 'FongBar', 'baz', 'foo'],
|
\ ['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):
|
Execute(Prefix filtering should work for completion items):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [{'word': 'FooBar'}, {'word': 'foo'}],
|
\ [{'word': 'FooBar'}, {'word': 'foo'}],
|
||||||
\ ale#completion#Filter(
|
\ ale#completion#Filter(
|
||||||
\ bufnr(''),
|
\ bufnr(''),
|
||||||
|
\ '',
|
||||||
\ [
|
\ [
|
||||||
\ {'word': 'FooBar'},
|
\ {'word': 'FooBar'},
|
||||||
\ {'word': 'FongBar'},
|
\ {'word': 'FongBar'},
|
||||||
@@ -40,6 +41,7 @@ Execute(Prefix filtering should work for completion items):
|
|||||||
\ ],
|
\ ],
|
||||||
\ ale#completion#Filter(
|
\ ale#completion#Filter(
|
||||||
\ bufnr(''),
|
\ bufnr(''),
|
||||||
|
\ '',
|
||||||
\ [
|
\ [
|
||||||
\ {'word': 'FooBar'},
|
\ {'word': 'FooBar'},
|
||||||
\ {'word': 'FongBar'},
|
\ {'word': 'FongBar'},
|
||||||
@@ -56,6 +58,7 @@ Execute(Excluding words from completion results should work):
|
|||||||
\ [{'word': 'Italian'}],
|
\ [{'word': 'Italian'}],
|
||||||
\ ale#completion#Filter(
|
\ ale#completion#Filter(
|
||||||
\ bufnr(''),
|
\ bufnr(''),
|
||||||
|
\ '',
|
||||||
\ [
|
\ [
|
||||||
\ {'word': 'Italian'},
|
\ {'word': 'Italian'},
|
||||||
\ {'word': 'it'},
|
\ {'word': 'it'},
|
||||||
@@ -67,6 +70,7 @@ Execute(Excluding words from completion results should work):
|
|||||||
\ [{'word': 'Deutsch'}],
|
\ [{'word': 'Deutsch'}],
|
||||||
\ ale#completion#Filter(
|
\ ale#completion#Filter(
|
||||||
\ bufnr(''),
|
\ bufnr(''),
|
||||||
|
\ '',
|
||||||
\ [
|
\ [
|
||||||
\ {'word': 'describe'},
|
\ {'word': 'describe'},
|
||||||
\ {'word': 'Deutsch'},
|
\ {'word': 'Deutsch'},
|
||||||
@@ -78,6 +82,7 @@ Execute(Excluding words from completion results should work):
|
|||||||
\ [{'word': 'Deutsch'}],
|
\ [{'word': 'Deutsch'}],
|
||||||
\ ale#completion#Filter(
|
\ ale#completion#Filter(
|
||||||
\ bufnr(''),
|
\ bufnr(''),
|
||||||
|
\ '',
|
||||||
\ [
|
\ [
|
||||||
\ {'word': 'describe'},
|
\ {'word': 'describe'},
|
||||||
\ {'word': 'Deutsch'},
|
\ {'word': 'Deutsch'},
|
||||||
@@ -90,19 +95,26 @@ Execute(Excluding words from completion results should work with lists of String
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['Italian'],
|
\ ['Italian'],
|
||||||
\ ale#completion#Filter(bufnr(''), ['Italian', 'it'], 'it')
|
\ ale#completion#Filter(bufnr(''), '', ['Italian', 'it'], 'it')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['Deutsch'],
|
\ ['Deutsch'],
|
||||||
\ ale#completion#Filter(bufnr(''), ['describe', 'Deutsch'], 'de')
|
\ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], 'de')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['Deutsch'],
|
\ ['Deutsch'],
|
||||||
\ ale#completion#Filter(bufnr(''), ['describe', 'Deutsch'], '.')
|
\ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], '.')
|
||||||
|
|
||||||
Execute(Filtering shouldn't modify the original list):
|
Execute(Filtering shouldn't modify the original list):
|
||||||
let b:ale_completion_excluded_words = ['it', 'describe']
|
let b:ale_completion_excluded_words = ['it', 'describe']
|
||||||
let b:suggestions = [{'word': '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 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'}]
|
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, '::')
|
||||||
|
|||||||
Reference in New Issue
Block a user