Fix #2326 - ALEComplete no longer replaces completeopt

This commit is contained in:
w0rp 2019-03-08 21:32:05 +00:00
parent be2c0c3af5
commit 413529f603
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
6 changed files with 79 additions and 72 deletions

View File

@ -165,14 +165,18 @@ function! s:ReplaceCompletionOptions() abort
let &l:omnifunc = 'ale#completion#OmniFunc' let &l:omnifunc = 'ale#completion#OmniFunc'
if !exists('b:ale_old_completopt') let l:info = get(b:, 'ale_completion_info', {})
let b:ale_old_completopt = &l:completeopt
endif
if &l:completeopt =~# 'preview' if !get(l:info, 'manual')
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert' if !exists('b:ale_old_completeopt')
else let b:ale_old_completeopt = &l:completeopt
let &l:completeopt = 'menu,menuone,noselect,noinsert' endif
if &l:completeopt =~# 'preview'
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert'
else
let &l:completeopt = 'menu,menuone,noselect,noinsert'
endif
endif endif
endfunction endfunction
@ -186,9 +190,9 @@ function! ale#completion#RestoreCompletionOptions() abort
unlet b:ale_old_omnifunc unlet b:ale_old_omnifunc
endif endif
if exists('b:ale_old_completopt') if exists('b:ale_old_completeopt')
let &l:completeopt = b:ale_old_completopt let &l:completeopt = b:ale_old_completeopt
unlet b:ale_old_completopt unlet b:ale_old_completeopt
endif endif
endfunction endfunction
@ -503,22 +507,14 @@ function! s:OnReady(linter, lsp_details) abort
endif endif
endfunction endfunction
function! ale#completion#GetCompletions() abort
if !g:ale_completion_enabled
return
endif
call ale#completion#AlwaysGetCompletions(1)
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(need_prefix) abort function! ale#completion#GetCompletions(manual) abort
let [l:line, l:column] = getpos('.')[1:2] let [l:line, l:column] = getpos('.')[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 a:need_prefix && empty(l:prefix) if !a:manual && empty(l:prefix)
return return
endif endif
@ -531,6 +527,7 @@ function! ale#completion#AlwaysGetCompletions(need_prefix) abort
\ 'prefix': l:prefix, \ 'prefix': l:prefix,
\ 'conn_id': 0, \ 'conn_id': 0,
\ 'request_id': 0, \ 'request_id': 0,
\ 'manual': a:manual,
\} \}
let l:buffer = bufnr('') let l:buffer = bufnr('')
@ -544,6 +541,10 @@ function! ale#completion#AlwaysGetCompletions(need_prefix) abort
endfunction endfunction
function! s:TimerHandler(...) abort function! s:TimerHandler(...) abort
if !g:ale_completion_enabled
return
endif
let s:timer_id = -1 let s:timer_id = -1
let [l:line, l:column] = getpos('.')[1:2] let [l:line, l:column] = getpos('.')[1:2]
@ -551,7 +552,7 @@ function! s:TimerHandler(...) abort
" When running the timer callback, we have to be sure that the cursor " When running the timer callback, we have to be sure that the cursor
" hasn't moved from where it was when we requested completions by typing. " hasn't moved from where it was when we requested completions by typing.
if s:timer_pos == [l:line, l:column] && ale#util#Mode() is# 'i' if s:timer_pos == [l:line, l:column] && ale#util#Mode() is# 'i'
call ale#completion#GetCompletions() call ale#completion#GetCompletions(0)
endif endif
endfunction endfunction

View File

@ -699,13 +699,13 @@ with |g:ale_completion_excluded_words| or |b:ale_completion_excluded_words|.
The |ALEComplete| command can be used to show completion suggestions manually, The |ALEComplete| command can be used to show completion suggestions manually,
even when |g:ale_completion_enabled| is set to `0`. even when |g:ale_completion_enabled| is set to `0`.
*ale-completion-completopt-bug* *ale-completion-completeopt-bug*
ALE implements completion as you type by temporarily adjusting |completeopt| Automatic completion replaces |completeopt| before opening the omnicomplete
before opening the omnicomplete menu with <C-x><C-o>. In some versions of Vim, menu with <C-x><C-o>. In some versions of Vim, the value set for the option
the value set for the option will not be respected. If you experience issues will not be respected. If you experience issues with Vim automatically
with Vim automatically inserting text while you type, set the following option inserting text while you type, set the following option in vimrc, and your
in vimrc, and your issues should go away. > issues should go away. >
set completeopt=menu,menuone,preview,noselect,noinsert set completeopt=menu,menuone,preview,noselect,noinsert
< <

View File

@ -216,7 +216,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(0) command! -bar ALEComplete :call ale#completion#GetCompletions(1)
" <Plug> mappings for commands " <Plug> mappings for commands
nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return> nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return>

View File

@ -27,7 +27,7 @@ Before:
let g:get_completions_called = 0 let g:get_completions_called = 0
" We just want to check if the function is called. " We just want to check if the function is called.
function! ale#completion#GetCompletions() function! ale#completion#GetCompletions(manual)
let g:get_completions_called = 1 let g:get_completions_called = 1
endfunction endfunction
@ -53,7 +53,7 @@ After:
unlet! g:fake_mode unlet! g:fake_mode
unlet! g:get_completions_called unlet! g:get_completions_called
unlet! b:ale_old_omnifunc unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt unlet! b:ale_old_completeopt
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response unlet! b:ale_completion_response
unlet! b:ale_completion_parser unlet! b:ale_completion_parser
@ -86,7 +86,7 @@ Execute(ale#completion#GetCompletions should not be called when the cursor posit
call setpos('.', [bufnr(''), 1, 2, 0]) call setpos('.', [bufnr(''), 1, 2, 0])
" We just want to check if the function is called. " We just want to check if the function is called.
function! ale#completion#GetCompletions() function! ale#completion#GetCompletions(manual)
let g:get_completions_called = 1 let g:get_completions_called = 1
endfunction endfunction
@ -105,7 +105,7 @@ Execute(ale#completion#GetCompletions should not be called if you switch to norm
let g:fake_mode = 'n' let g:fake_mode = 'n'
" We just want to check if the function is called. " We just want to check if the function is called.
function! ale#completion#GetCompletions() function! ale#completion#GetCompletions(manual)
let g:get_completions_called = 1 let g:get_completions_called = 1
endfunction endfunction
@ -138,7 +138,7 @@ Execute(ale#completion#Show() should remember the completeopt setting and replac
call ale#completion#Show('Response', 'Parser') call ale#completion#Show('Response', 'Parser')
AssertEqual 'menu', b:ale_old_completopt AssertEqual 'menu', b:ale_old_completeopt
AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
@ -150,19 +150,32 @@ Execute(ale#completion#Show() should set the preview option if it's set):
call ale#completion#Show('Response', 'Parser') call ale#completion#Show('Response', 'Parser')
AssertEqual 'menu,preview', b:ale_old_completopt AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
sleep 1ms sleep 1ms
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
Execute(ale#completion#Show() should not replace the completeopt setting for manual completion):
let b:ale_completion_info = {'manual': 1}
let &l:completeopt = 'menu,preview'
call ale#completion#Show('Response', 'Parser')
Assert !exists('b:ale_old_completeopt')
AssertEqual [], g:feedkeys_calls
sleep 1ms
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
Execute(ale#completion#OmniFunc() should also remember the completeopt setting and replace it): Execute(ale#completion#OmniFunc() should also remember the completeopt setting and replace it):
let &l:completeopt = 'menu' let &l:completeopt = 'menu'
call ale#completion#OmniFunc(0, '') call ale#completion#OmniFunc(0, '')
AssertEqual 'menu', b:ale_old_completopt AssertEqual 'menu', b:ale_old_completeopt
AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt
Execute(ale#completion#OmniFunc() should set the preview option if it's set): Execute(ale#completion#OmniFunc() should set the preview option if it's set):
@ -170,7 +183,7 @@ Execute(ale#completion#OmniFunc() should set the preview option if it's set):
call ale#completion#OmniFunc(0, '') call ale#completion#OmniFunc(0, '')
AssertEqual 'menu,preview', b:ale_old_completopt AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
Execute(ale#completion#Show() should make the correct feedkeys() call): Execute(ale#completion#Show() should make the correct feedkeys() call):
@ -188,7 +201,7 @@ Execute(ale#completion#Show() shouldn't do anything if you switch back to normal
AssertEqual 'menu,preview', &l:completeopt AssertEqual 'menu,preview', &l:completeopt
Assert !exists('b:ale_old_omnifunc') Assert !exists('b:ale_old_omnifunc')
Assert !exists('b:ale_old_completopt') Assert !exists('b:ale_old_completeopt')
Assert !exists('b:ale_completion_response') Assert !exists('b:ale_completion_response')
Assert !exists('b:ale_completion_parser') Assert !exists('b:ale_completion_parser')
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
@ -209,12 +222,12 @@ Execute(ale#completion#Done() should restore old omnifunc values):
Assert !has_key(b:, 'ale_old_omnifunc') Assert !has_key(b:, 'ale_old_omnifunc')
Execute(ale#completion#Done() should restore the old completeopt setting): Execute(ale#completion#Done() should restore the old completeopt setting):
let b:ale_old_completopt = 'menu' let b:ale_old_completeopt = 'menu'
call ale#completion#Done() call ale#completion#Done()
AssertEqual 'menu', &l:completeopt AssertEqual 'menu', &l:completeopt
Assert !has_key(b:, 'ale_old_completopt') Assert !has_key(b:, 'ale_old_completeopt')
Execute(ale#completion#Done() should leave settings alone when none were remembered): Execute(ale#completion#Done() should leave settings alone when none were remembered):
let &l:omnifunc = 'BazBoz' let &l:omnifunc = 'BazBoz'
@ -236,7 +249,7 @@ Execute(The completion request_id should be reset when queuing again):
Execute(b:ale_completion_info should be set up correctly when requesting completions): Execute(b:ale_completion_info should be set up correctly when requesting completions):
call setpos('.', [bufnr(''), 3, 14, 0]) call setpos('.', [bufnr(''), 3, 14, 0])
call ale#completion#GetCompletions() call ale#completion#GetCompletions(0)
AssertEqual AssertEqual
\ { \ {
@ -246,6 +259,23 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
\ 'line_length': 14, \ 'line_length': 14,
\ 'line': 3, \ 'line': 3,
\ 'prefix': 'ab', \ 'prefix': 'ab',
\ 'manual': 0,
\ },
\ b:ale_completion_info
Execute(b:ale_completion_info should be set up correctly when requesting completions):
call setpos('.', [bufnr(''), 3, 14, 0])
ALEComplete
AssertEqual
\ {
\ 'request_id': 0,
\ 'conn_id': 0,
\ 'column': 14,
\ 'line_length': 14,
\ 'line': 3,
\ 'prefix': 'ab',
\ 'manual': 1,
\ }, \ },
\ b:ale_completion_info \ b:ale_completion_info
@ -264,7 +294,7 @@ Execute(The correct keybinds should be configured):
Execute(Running the normal mode <Plug> keybind should reset the settings): Execute(Running the normal mode <Plug> keybind should reset the settings):
let b:ale_old_omnifunc = 'FooBar' let b:ale_old_omnifunc = 'FooBar'
let b:ale_old_completopt = 'menu' let b:ale_old_completeopt = 'menu'
" We can't run the keybind, but we can call the function. " We can't run the keybind, but we can call the function.
call ale#completion#RestoreCompletionOptions() call ale#completion#RestoreCompletionOptions()
@ -272,4 +302,4 @@ Execute(Running the normal mode <Plug> keybind should reset the settings):
AssertEqual 'FooBar', &l:omnifunc AssertEqual 'FooBar', &l:omnifunc
AssertEqual 'menu', &l:completeopt AssertEqual 'menu', &l:completeopt
Assert !has_key(b:, 'ale_old_omnifunc') Assert !has_key(b:, 'ale_old_omnifunc')
Assert !has_key(b:, 'ale_old_completopt') Assert !has_key(b:, 'ale_old_completeopt')

View File

@ -67,7 +67,7 @@ After:
unlet! g:conn_id unlet! g:conn_id
unlet! g:Callback unlet! g:Callback
unlet! b:ale_old_omnifunc unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt unlet! b:ale_old_completeopt
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response unlet! b:ale_completion_response
unlet! b:ale_completion_parser unlet! b:ale_completion_parser
@ -102,7 +102,7 @@ Execute(The right message should be sent for the initial tsserver request):
" The cursor position needs to match what was saved before. " The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 3, 0]) call setpos('.', [bufnr(''), 1, 3, 0])
call ale#completion#GetCompletions() call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet. " We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback) AssertEqual '''''', string(g:Callback)
@ -129,6 +129,7 @@ Execute(The right message should be sent for the initial tsserver request):
\ 'request_id': 1, \ 'request_id': 1,
\ 'line': 1, \ 'line': 1,
\ 'prefix': 'fo', \ 'prefix': 'fo',
\ 'manual': 0,
\ }, \ },
\ get(b:, 'ale_completion_info', {}) \ get(b:, 'ale_completion_info', {})
@ -190,7 +191,7 @@ Execute(The right message should be sent for the initial LSP request):
" The cursor position needs to match what was saved before. " The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 5, 0]) call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions() call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet. " We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback) AssertEqual '''''', string(g:Callback)
@ -233,6 +234,7 @@ Execute(The right message should be sent for the initial LSP request):
\ 'request_id': 1, \ 'request_id': 1,
\ 'line': 1, \ 'line': 1,
\ 'prefix': 'fo', \ 'prefix': 'fo',
\ 'manual': 0,
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter', \ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
\ }, \ },
\ get(b:, 'ale_completion_info', {}) \ get(b:, 'ale_completion_info', {})
@ -258,7 +260,7 @@ Execute(Two completion requests shouldn't be sent in a row):
" The cursor position needs to match what was saved before. " The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 5, 0]) call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions() call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet. " We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback) AssertEqual '''''', string(g:Callback)

View File

@ -1,26 +0,0 @@
Before:
function! MockAlwaysGetCompletions() abort
let g:get_completions_called = 0
let g:always_get_completions_argument = -1
function! ale#completion#AlwaysGetCompletions(need_prefix) abort
let g:get_completions_called = 1
let g:always_get_completions_argument = a:need_prefix
endfunction
endfunction
call MockAlwaysGetCompletions()
After:
unlet! g:get_completions_called
unlet! g:always_get_completions_argument
delfunction MockAlwaysGetCompletions
delfunction ale#completion#AlwaysGetCompletions
runtime autoload/ale/completion.vim
Execute(ale#completion#AlwaysGetCompletions should be called when ALEComplete is executed):
AssertEqual 0, g:get_completions_called
ALEComplete
AssertEqual 1, g:get_completions_called
AssertEqual 0, g:always_get_completions_argument