Increase the default maximum completion suggestions to a more useful but safe level, and filter before requesting details, which is faster
This commit is contained in:
parent
8cc7cd3aa1
commit
be4347084e
@ -43,7 +43,7 @@ let s:omni_start_map = {
|
||||
\ 'typescript': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$',
|
||||
\}
|
||||
|
||||
function! ale#completion#FilterSuggestionsByPrefix(suggestions, prefix) abort
|
||||
function! ale#completion#Filter(suggestions, prefix) abort
|
||||
" For completing...
|
||||
" foo.
|
||||
" ^
|
||||
@ -57,14 +57,17 @@ function! ale#completion#FilterSuggestionsByPrefix(suggestions, prefix) abort
|
||||
" Filter suggestions down to those starting with the prefix we used for
|
||||
" finding suggestions in the first place.
|
||||
"
|
||||
" Some completion tools will
|
||||
" include suggestions which don't even start with the characters we have
|
||||
" already typed.
|
||||
for l:suggestion in a:suggestions
|
||||
" Some completion tools will include suggestions which don't even start
|
||||
" with the characters we have already typed.
|
||||
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) == type('') ? l:item : l:item.word
|
||||
|
||||
" Add suggestions if the suggestion starts with a case-insensitive
|
||||
" match for the prefix.
|
||||
if l:suggestion.word[: len(a:prefix) - 1] is? a:prefix
|
||||
call add(l:filtered_suggestions, l:suggestion)
|
||||
if l:word[: len(a:prefix) - 1] is? a:prefix
|
||||
call add(l:filtered_suggestions, l:item)
|
||||
endif
|
||||
endfor
|
||||
|
||||
@ -98,12 +101,7 @@ function! ale#completion#OmniFunc(findstart, base) abort
|
||||
unlet b:ale_completion_response
|
||||
unlet b:ale_completion_parser
|
||||
|
||||
let l:prefix = b:ale_completion_info.prefix
|
||||
|
||||
let b:ale_completion_result = ale#completion#FilterSuggestionsByPrefix(
|
||||
\ function(l:parser)(l:response),
|
||||
\ l:prefix
|
||||
\)[: g:ale_completion_max_suggestions]
|
||||
let b:ale_completion_result = function(l:parser)(l:response)
|
||||
endif
|
||||
|
||||
call s:ReplaceCompleteopt()
|
||||
@ -191,7 +189,7 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
|
||||
return l:results
|
||||
endfunction
|
||||
|
||||
function! s:HandleTSServerLSPResponse(conn_id, response) abort
|
||||
function! ale#completion#HandleTSServerLSPResponse(conn_id, response) abort
|
||||
if !s:CompletionStillValid(get(a:response, 'request_seq'))
|
||||
return
|
||||
endif
|
||||
@ -203,7 +201,10 @@ function! s:HandleTSServerLSPResponse(conn_id, response) abort
|
||||
let l:command = get(a:response, 'command', '')
|
||||
|
||||
if l:command is# 'completions'
|
||||
let l:names = ale#completion#ParseTSServerCompletions(a:response)
|
||||
let l:names = ale#completion#Filter(
|
||||
\ ale#completion#ParseTSServerCompletions(a:response),
|
||||
\ b:ale_completion_info.prefix,
|
||||
\)[: g:ale_completion_max_suggestions - 1]
|
||||
|
||||
if !empty(l:names)
|
||||
let b:ale_completion_info.request_id = ale#lsp#Send(
|
||||
@ -229,7 +230,7 @@ function! s:GetLSPCompletions(linter) abort
|
||||
let l:lsp_details = ale#linter#StartLSP(
|
||||
\ l:buffer,
|
||||
\ a:linter,
|
||||
\ function('s:HandleTSServerLSPResponse'),
|
||||
\ function('ale#completion#HandleTSServerLSPResponse'),
|
||||
\)
|
||||
|
||||
if empty(l:lsp_details)
|
||||
|
@ -296,7 +296,7 @@ g:ale_completion_enabled *g:ale_completion_enabled*
|
||||
g:ale_completion_max_suggestions *g:ale_completion_max_suggestions*
|
||||
|
||||
Type: |Number|
|
||||
Default: `20`
|
||||
Default: `50`
|
||||
|
||||
The maximum number of items ALE will suggest in completion menus for
|
||||
automatic completion.
|
||||
|
@ -190,7 +190,7 @@ call ale#Set('type_map', {})
|
||||
" Enable automatic completion with LSP servers and tsserver
|
||||
call ale#Set('completion_enabled', 0)
|
||||
call ale#Set('completion_delay', 100)
|
||||
call ale#Set('completion_max_suggestions', 20)
|
||||
call ale#Set('completion_max_suggestions', 50)
|
||||
|
||||
function! ALEInitAuGroups() abort
|
||||
" This value used to be a Boolean as a Number, and is now a String.
|
||||
|
@ -1,6 +1,7 @@
|
||||
Before:
|
||||
Save g:ale_completion_enabled
|
||||
Save g:ale_completion_delay
|
||||
Save g:ale_completion_max_suggestions
|
||||
Save &l:omnifunc
|
||||
Save &l:completeopt
|
||||
|
||||
@ -25,6 +26,7 @@ After:
|
||||
unlet! b:ale_completion_parser
|
||||
|
||||
runtime autoload/ale/completion.vim
|
||||
runtime autoload/ale/lsp.vim
|
||||
|
||||
if g:ale_completion_enabled
|
||||
call ale#completion#Enable()
|
||||
@ -108,6 +110,89 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||
\ ],
|
||||
\})
|
||||
|
||||
Execute(Prefix filtering should work for Lists of strings):
|
||||
AssertEqual
|
||||
\ ['FooBar', 'foo'],
|
||||
\ ale#completion#Filter(['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
|
||||
AssertEqual
|
||||
\ ['FooBar', 'FongBar', 'baz', 'foo'],
|
||||
\ ale#completion#Filter(['FooBar', 'FongBar', 'baz', 'foo'], '.')
|
||||
|
||||
Execute(Prefix filtering should work for completion items):
|
||||
AssertEqual
|
||||
\ [{'word': 'FooBar'}, {'word': 'foo'}],
|
||||
\ ale#completion#Filter(
|
||||
\ [
|
||||
\ {'word': 'FooBar'},
|
||||
\ {'word': 'FongBar'},
|
||||
\ {'word': 'baz'},
|
||||
\ {'word': 'foo'},
|
||||
\ ],
|
||||
\ 'foo'
|
||||
\ )
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {'word': 'FooBar'},
|
||||
\ {'word': 'FongBar'},
|
||||
\ {'word': 'baz'},
|
||||
\ {'word': 'foo'},
|
||||
\ ],
|
||||
\ ale#completion#Filter(
|
||||
\ [
|
||||
\ {'word': 'FooBar'},
|
||||
\ {'word': 'FongBar'},
|
||||
\ {'word': 'baz'},
|
||||
\ {'word': 'foo'},
|
||||
\ ],
|
||||
\ '.'
|
||||
\ )
|
||||
|
||||
Execute(The right message sent to the tsserver LSP when the first completion message is received):
|
||||
" The cursor position needs to match what was saved before.
|
||||
call setpos('.', [bufnr(''), 1, 1, 0])
|
||||
let b:ale_completion_info = {
|
||||
\ 'conn_id': 123,
|
||||
\ 'prefix': 'f',
|
||||
\ 'request_id': 4,
|
||||
\ 'line': 1,
|
||||
\ 'column': 1,
|
||||
\}
|
||||
" We should only show up to this many suggestions.
|
||||
let g:ale_completion_max_suggestions = 3
|
||||
|
||||
" Replace the Send function for LSP, so we can monitor calls to it.
|
||||
function! ale#lsp#Send(conn_id, message) abort
|
||||
let g:test_vars.message = a:message
|
||||
endfunction
|
||||
|
||||
" Handle the response for completions.
|
||||
call ale#completion#HandleTSServerLSPResponse(123, {
|
||||
\ 'request_seq': 4,
|
||||
\ 'command': 'completions',
|
||||
\ 'body': [
|
||||
\ {'name': 'Baz'},
|
||||
\ {'name': 'dingDong'},
|
||||
\ {'name': 'Foo'},
|
||||
\ {'name': 'FooBar'},
|
||||
\ {'name': 'frazzle'},
|
||||
\ {'name': 'FFS'},
|
||||
\ ],
|
||||
\})
|
||||
|
||||
" The entry details messages should have been sent.
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 0,
|
||||
\ 'ts@completionEntryDetails',
|
||||
\ {
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'entryNames': ['Foo', 'FooBar', 'frazzle'],
|
||||
\ 'offset': 1,
|
||||
\ 'line': 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ g:test_vars.message
|
||||
|
||||
Given typescript():
|
||||
let abc = y.
|
||||
let foo = ab
|
||||
|
Loading…
Reference in New Issue
Block a user