Optimize ale#completion#Filter when prefix is ""
This commit is contained in:
parent
9bcf8a2336
commit
b1b05e6e66
@ -89,6 +89,10 @@ function! ale#completion#GetPrefix(filetype, line, column) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#completion#GetTriggerCharacter(filetype, prefix) abort
|
function! ale#completion#GetTriggerCharacter(filetype, prefix) abort
|
||||||
|
if empty(a:prefix)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
let l:char_list = s:GetFiletypeValue(s:trigger_character_map, a:filetype)
|
let l:char_list = s:GetFiletypeValue(s:trigger_character_map, a:filetype)
|
||||||
|
|
||||||
if index(l:char_list, a:prefix) >= 0
|
if index(l:char_list, a:prefix) >= 0
|
||||||
@ -100,33 +104,38 @@ endfunction
|
|||||||
|
|
||||||
function! ale#completion#Filter(buffer, filetype, 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...
|
if empty(a:prefix)
|
||||||
" foo.
|
|
||||||
" ^
|
|
||||||
" We need to include all of the given suggestions.
|
|
||||||
if index(l:triggers, a:prefix) >= 0 || empty(a:prefix)
|
|
||||||
let l:filtered_suggestions = a:suggestions
|
let l:filtered_suggestions = a:suggestions
|
||||||
else
|
else
|
||||||
let l:filtered_suggestions = []
|
let l:triggers = s:GetFiletypeValue(s:trigger_character_map, a:filetype)
|
||||||
|
|
||||||
" Filter suggestions down to those starting with the prefix we used for
|
" For completing...
|
||||||
" finding suggestions in the first place.
|
" foo.
|
||||||
"
|
" ^
|
||||||
" Some completion tools will include suggestions which don't even start
|
" We need to include all of the given suggestions.
|
||||||
" with the characters we have already typed.
|
if index(l:triggers, a:prefix) >= 0 || empty(a:prefix)
|
||||||
for l:item in a:suggestions
|
let l:filtered_suggestions = a:suggestions
|
||||||
" A List of String values or a List of completion item Dictionaries
|
else
|
||||||
" is accepted here.
|
let l:filtered_suggestions = []
|
||||||
let l:word = type(l:item) is v:t_string ? l:item : l:item.word
|
|
||||||
|
|
||||||
" Add suggestions if the suggestion starts with a case-insensitive
|
" Filter suggestions down to those starting with the prefix we
|
||||||
" match for the prefix.
|
" used for finding suggestions in the first place.
|
||||||
if l:word[: len(a:prefix) - 1] is? a:prefix
|
"
|
||||||
call add(l:filtered_suggestions, l:item)
|
" Some completion tools will include suggestions which don't even
|
||||||
endif
|
" start with the characters we have already typed.
|
||||||
endfor
|
for l:item in a:suggestions
|
||||||
|
" A List of String values or a List of completion item
|
||||||
|
" Dictionaries is accepted here.
|
||||||
|
let l:word = type(l:item) is v:t_string ? l:item : l:item.word
|
||||||
|
|
||||||
|
" Add suggestions if the suggestion starts with a
|
||||||
|
" case-insensitive match for the prefix.
|
||||||
|
if l:word[: len(a:prefix) - 1] is? a:prefix
|
||||||
|
call add(l:filtered_suggestions, l:item)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !empty(l:excluded_words)
|
if !empty(l:excluded_words)
|
||||||
@ -514,13 +523,12 @@ endfunction
|
|||||||
|
|
||||||
" This function can be used to manually trigger autocomplete, even when
|
" This function can be used to manually trigger autocomplete, even when
|
||||||
" g:ale_completion_enabled is set to false
|
" g:ale_completion_enabled is set to false
|
||||||
function! ale#completion#AlwaysGetCompletions(...) abort
|
function! ale#completion#AlwaysGetCompletions(need_prefix) abort
|
||||||
let l:need_prefix = get(a:, 1, 0)
|
|
||||||
let [l:line, l:column] = getcurpos()[1:2]
|
let [l:line, l:column] = getcurpos()[1:2]
|
||||||
|
|
||||||
let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column)
|
let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column)
|
||||||
|
|
||||||
if l:need_prefix && empty(l:prefix)
|
if a:need_prefix && empty(l:prefix)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ command! -bar ALEDocumentation :call ale#hover#ShowDocumentationAtCursor()
|
|||||||
" Search for appearances of a symbol, such as a type name or function name.
|
" Search for appearances of a symbol, such as a type name or function name.
|
||||||
command! -nargs=1 ALESymbolSearch :call ale#symbol#Search(<q-args>)
|
command! -nargs=1 ALESymbolSearch :call ale#symbol#Search(<q-args>)
|
||||||
|
|
||||||
command! -bar ALEComplete :call ale#completion#AlwaysGetCompletions()
|
command! -bar ALEComplete :call ale#completion#AlwaysGetCompletions(0)
|
||||||
|
|
||||||
" <Plug> mappings for commands
|
" <Plug> mappings for commands
|
||||||
nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return>
|
nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return>
|
||||||
|
@ -105,6 +105,9 @@ Execute(Excluding words from completion results should work with lists of String
|
|||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['Deutsch'],
|
\ ['Deutsch'],
|
||||||
\ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], '.')
|
\ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], '.')
|
||||||
|
AssertEqual
|
||||||
|
\ ['Deutsch'],
|
||||||
|
\ ale#completion#Filter(bufnr(''), '', ['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']
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
Before:
|
Before:
|
||||||
function! MockAlwaysGetCompletions() abort
|
function! MockAlwaysGetCompletions() abort
|
||||||
let g:get_completions_called = 0
|
let g:get_completions_called = 0
|
||||||
|
let g:always_get_completions_argument = -1
|
||||||
|
|
||||||
function! ale#completion#AlwaysGetCompletions() abort
|
function! ale#completion#AlwaysGetCompletions(need_prefix) abort
|
||||||
let g:get_completions_called = 1
|
let g:get_completions_called = 1
|
||||||
|
let g:always_get_completions_argument = a:need_prefix
|
||||||
endfunction
|
endfunction
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ Before:
|
|||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! g:get_completions_called
|
unlet! g:get_completions_called
|
||||||
|
unlet! g:always_get_completions_argument
|
||||||
delfunction MockAlwaysGetCompletions
|
delfunction MockAlwaysGetCompletions
|
||||||
delfunction ale#completion#AlwaysGetCompletions
|
delfunction ale#completion#AlwaysGetCompletions
|
||||||
|
|
||||||
@ -20,3 +23,4 @@ Execute(ale#completion#AlwaysGetCompletions should be called when ALEComplete is
|
|||||||
AssertEqual 0, g:get_completions_called
|
AssertEqual 0, g:get_completions_called
|
||||||
ALEComplete
|
ALEComplete
|
||||||
AssertEqual 1, g:get_completions_called
|
AssertEqual 1, g:get_completions_called
|
||||||
|
AssertEqual 0, g:always_get_completions_argument
|
||||||
|
Loading…
Reference in New Issue
Block a user