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
6 changed files with 79 additions and 72 deletions

View File

@@ -27,7 +27,7 @@ Before:
let g:get_completions_called = 0
" 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
endfunction
@@ -53,7 +53,7 @@ After:
unlet! g:fake_mode
unlet! g:get_completions_called
unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt
unlet! b:ale_old_completeopt
unlet! b:ale_completion_info
unlet! b:ale_completion_response
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])
" 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
endfunction
@@ -105,7 +105,7 @@ Execute(ale#completion#GetCompletions should not be called if you switch to norm
let g:fake_mode = 'n'
" 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
endfunction
@@ -138,7 +138,7 @@ Execute(ale#completion#Show() should remember the completeopt setting and replac
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 [], 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')
AssertEqual 'menu,preview', b:ale_old_completopt
AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
AssertEqual [], g:feedkeys_calls
sleep 1ms
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):
let &l:completeopt = 'menu'
call ale#completion#OmniFunc(0, '')
AssertEqual 'menu', b:ale_old_completopt
AssertEqual 'menu', b:ale_old_completeopt
AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt
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, '')
AssertEqual 'menu,preview', b:ale_old_completopt
AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
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
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_parser')
AssertEqual [], g:feedkeys_calls
@@ -209,12 +222,12 @@ Execute(ale#completion#Done() should restore old omnifunc values):
Assert !has_key(b:, 'ale_old_omnifunc')
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()
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):
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):
call setpos('.', [bufnr(''), 3, 14, 0])
call ale#completion#GetCompletions()
call ale#completion#GetCompletions(0)
AssertEqual
\ {
@@ -246,6 +259,23 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
\ 'line_length': 14,
\ 'line': 3,
\ '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
@@ -264,7 +294,7 @@ Execute(The correct keybinds should be configured):
Execute(Running the normal mode <Plug> keybind should reset the settings):
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.
call ale#completion#RestoreCompletionOptions()
@@ -272,4 +302,4 @@ Execute(Running the normal mode <Plug> keybind should reset the settings):
AssertEqual 'FooBar', &l:omnifunc
AssertEqual 'menu', &l:completeopt
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:Callback
unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt
unlet! b:ale_old_completeopt
unlet! b:ale_completion_info
unlet! b:ale_completion_response
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.
call setpos('.', [bufnr(''), 1, 3, 0])
call ale#completion#GetCompletions()
call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)
@@ -129,6 +129,7 @@ Execute(The right message should be sent for the initial tsserver request):
\ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
\ 'manual': 0,
\ },
\ 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.
call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions()
call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)
@@ -233,6 +234,7 @@ Execute(The right message should be sent for the initial LSP request):
\ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
\ 'manual': 0,
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
\ },
\ 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.
call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions()
call ale#completion#GetCompletions(0)
" We shouldn't register the callback yet.
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