2017-11-26 12:24:18 +00:00
|
|
|
Before:
|
|
|
|
Save g:ale_completion_enabled
|
|
|
|
Save g:ale_completion_delay
|
|
|
|
Save g:ale_completion_max_suggestions
|
|
|
|
Save &l:omnifunc
|
|
|
|
Save &l:completeopt
|
|
|
|
|
2019-05-11 16:19:45 +00:00
|
|
|
unlet! b:ale_completion_enabled
|
2017-11-26 12:24:18 +00:00
|
|
|
let g:ale_completion_enabled = 1
|
|
|
|
let g:get_completions_called = 0
|
|
|
|
let g:feedkeys_calls = []
|
2018-07-16 16:57:07 +00:00
|
|
|
let g:fake_mode = 'i'
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2021-03-21 00:21:49 +00:00
|
|
|
let b:ale_linters = {
|
|
|
|
\ 'typescript': ['tsserver'],
|
|
|
|
\}
|
|
|
|
|
2018-07-04 07:52:08 +00:00
|
|
|
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert'
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
runtime autoload/ale/util.vim
|
|
|
|
|
2018-07-17 18:39:45 +00:00
|
|
|
function! ale#util#FeedKeys(string) abort
|
|
|
|
call add(g:feedkeys_calls, [a:string])
|
2017-11-26 12:24:18 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-07-16 16:57:07 +00:00
|
|
|
" Pretend we're in insert mode for most tests.
|
|
|
|
function! ale#util#Mode(...) abort
|
|
|
|
return g:fake_mode
|
|
|
|
endfunction
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
function! CheckCompletionCalled(expect_success) abort
|
|
|
|
let g:get_completions_called = 0
|
|
|
|
|
|
|
|
" We just want to check if the function is called.
|
2019-04-23 20:26:16 +00:00
|
|
|
function! ale#completion#GetCompletions(source)
|
2017-11-26 12:24:18 +00:00
|
|
|
let g:get_completions_called = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
2018-07-22 21:42:41 +00:00
|
|
|
|
|
|
|
" Run this check a few times, as it can fail randomly.
|
2020-08-29 15:31:47 +00:00
|
|
|
for l:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
2018-07-22 21:42:41 +00:00
|
|
|
call ale#completion#Queue()
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
if g:get_completions_called is a:expect_success
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
AssertEqual a:expect_success, g:get_completions_called
|
|
|
|
endfunction
|
|
|
|
|
2019-09-12 20:53:23 +00:00
|
|
|
let g:handle_code_action_called = 0
|
|
|
|
function! MockHandleCodeAction() abort
|
|
|
|
" delfunction! ale#code_action#HandleCodeAction
|
2020-10-15 20:56:21 +00:00
|
|
|
function! ale#code_action#HandleCodeAction(action, options) abort
|
|
|
|
Assert !get(a:options, 'should_save')
|
2019-09-12 20:53:23 +00:00
|
|
|
let g:handle_code_action_called += 1
|
|
|
|
endfunction
|
|
|
|
endfunction
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
After:
|
|
|
|
Restore
|
|
|
|
|
2019-05-11 16:19:45 +00:00
|
|
|
unlet! b:ale_completion_enabled
|
2018-07-17 18:39:45 +00:00
|
|
|
unlet! g:output
|
2018-07-16 16:57:07 +00:00
|
|
|
unlet! g:fake_mode
|
2017-11-26 12:24:18 +00:00
|
|
|
unlet! g:get_completions_called
|
2019-09-12 20:53:23 +00:00
|
|
|
unlet! g:handle_code_action_called
|
2017-11-26 12:24:18 +00:00
|
|
|
unlet! b:ale_old_omnifunc
|
2019-03-08 21:32:05 +00:00
|
|
|
unlet! b:ale_old_completeopt
|
2017-11-26 12:24:18 +00:00
|
|
|
unlet! b:ale_completion_info
|
2019-04-23 20:26:16 +00:00
|
|
|
unlet! b:ale_completion_result
|
2017-11-26 12:24:18 +00:00
|
|
|
unlet! b:ale_complete_done_time
|
2021-03-21 00:21:49 +00:00
|
|
|
unlet! b:ale_linters
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
delfunction CheckCompletionCalled
|
2019-09-12 20:53:23 +00:00
|
|
|
delfunction ale#code_action#HandleCodeAction
|
|
|
|
delfunction MockHandleCodeAction
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-08-17 17:40:05 +00:00
|
|
|
if exists('*CompleteCallback')
|
|
|
|
delfunction CompleteCallback
|
|
|
|
endif
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
" Stop any timers we left behind.
|
|
|
|
" This stops the tests from failing randomly.
|
|
|
|
call ale#completion#StopTimer()
|
|
|
|
|
2018-07-16 16:57:07 +00:00
|
|
|
" Reset the function. The runtime command below should fix this, but doesn't
|
|
|
|
" seem to fix it.
|
|
|
|
function! ale#util#Mode(...) abort
|
|
|
|
return call('mode', a:000)
|
|
|
|
endfunction
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
runtime autoload/ale/completion.vim
|
2019-09-12 20:53:23 +00:00
|
|
|
runtime autoload/ale/code_action.vim
|
2017-11-26 12:24:18 +00:00
|
|
|
runtime autoload/ale/util.vim
|
|
|
|
|
|
|
|
Execute(ale#completion#GetCompletions should be called when the cursor position stays the same):
|
|
|
|
call CheckCompletionCalled(1)
|
|
|
|
|
2019-05-11 16:19:45 +00:00
|
|
|
Execute(ale#completion#GetCompletions should not be called if the global setting is disabled):
|
|
|
|
let g:ale_completion_enabled = 0
|
|
|
|
call CheckCompletionCalled(0)
|
|
|
|
|
|
|
|
Execute(ale#completion#GetCompletions should not be called if the buffer setting is disabled):
|
|
|
|
let b:ale_completion_enabled = 0
|
|
|
|
call CheckCompletionCalled(0)
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
Given typescript():
|
|
|
|
let abc = y.
|
|
|
|
let foo = ab
|
|
|
|
let foo = (ab)
|
|
|
|
|
|
|
|
Execute(ale#completion#GetCompletions should not be called when the cursor position changes):
|
|
|
|
call setpos('.', [bufnr(''), 1, 2, 0])
|
|
|
|
|
|
|
|
" We just want to check if the function is called.
|
2019-04-23 20:26:16 +00:00
|
|
|
function! ale#completion#GetCompletions(source)
|
2017-11-26 12:24:18 +00:00
|
|
|
let g:get_completions_called = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
|
|
|
|
" Change the cursor position before the callback is triggered.
|
|
|
|
call setpos('.', [bufnr(''), 2, 2, 0])
|
|
|
|
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
Assert !g:get_completions_called
|
|
|
|
|
2018-07-16 16:57:07 +00:00
|
|
|
Execute(ale#completion#GetCompletions should not be called if you switch to normal mode):
|
|
|
|
let &l:completeopt = 'menu,preview'
|
|
|
|
let g:fake_mode = 'n'
|
|
|
|
|
|
|
|
" We just want to check if the function is called.
|
2019-04-23 20:26:16 +00:00
|
|
|
function! ale#completion#GetCompletions(source)
|
2018-07-16 16:57:07 +00:00
|
|
|
let g:get_completions_called = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
Assert !g:get_completions_called
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
Execute(Completion should not be done shortly after the CompleteDone function):
|
|
|
|
call CheckCompletionCalled(1)
|
|
|
|
call ale#completion#Done()
|
|
|
|
call CheckCompletionCalled(0)
|
|
|
|
|
|
|
|
Execute(ale#completion#Show() should remember the omnifunc setting and replace it):
|
|
|
|
let &l:omnifunc = 'FooBar'
|
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
AssertEqual 'FooBar', b:ale_old_omnifunc
|
2019-05-16 23:57:52 +00:00
|
|
|
AssertEqual 'ale#completion#AutomaticOmniFunc', &l:omnifunc
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2018-07-26 22:08:38 +00:00
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
|
|
|
|
2017-11-26 12:24:18 +00:00
|
|
|
Execute(ale#completion#Show() should remember the completeopt setting and replace it):
|
|
|
|
let &l:completeopt = 'menu'
|
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-03-08 21:32:05 +00:00
|
|
|
AssertEqual 'menu', b:ale_old_completeopt
|
2021-06-19 09:57:34 +00:00
|
|
|
AssertEqual 'menu,menuone,noinsert', &l:completeopt
|
2018-07-04 07:52:08 +00:00
|
|
|
|
2018-07-26 22:08:38 +00:00
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
|
|
|
|
2018-07-04 07:52:08 +00:00
|
|
|
Execute(ale#completion#Show() should set the preview option if it's set):
|
|
|
|
let &l:completeopt = 'menu,preview'
|
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2018-07-04 07:52:08 +00:00
|
|
|
|
2019-03-08 21:32:05 +00:00
|
|
|
AssertEqual 'menu,preview', b:ale_old_completeopt
|
2021-06-19 09:57:34 +00:00
|
|
|
AssertEqual 'menu,menuone,noinsert,preview', &l:completeopt
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2018-07-26 22:08:38 +00:00
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
|
|
|
|
2019-03-08 21:32:05 +00:00
|
|
|
Execute(ale#completion#Show() should not replace the completeopt setting for manual completion):
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-manual'}
|
2019-03-08 21:32:05 +00:00
|
|
|
|
|
|
|
let &l:completeopt = 'menu,preview'
|
|
|
|
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2019-03-08 21:32:05 +00:00
|
|
|
|
|
|
|
Assert !exists('b:ale_old_completeopt')
|
|
|
|
|
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
|
|
|
|
2019-05-16 23:57:52 +00:00
|
|
|
Execute(ale#completion#AutomaticOmniFunc() should also remember the completeopt setting and replace it):
|
2021-06-19 09:57:34 +00:00
|
|
|
let &l:completeopt = 'menu,noselect'
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-16 23:57:52 +00:00
|
|
|
call ale#completion#AutomaticOmniFunc(0, '')
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2021-06-19 09:57:34 +00:00
|
|
|
AssertEqual 'menu,noselect', b:ale_old_completeopt
|
|
|
|
AssertEqual 'menu,menuone,noinsert,noselect', &l:completeopt
|
2018-07-04 07:52:08 +00:00
|
|
|
|
2019-05-16 23:57:52 +00:00
|
|
|
Execute(ale#completion#AutomaticOmniFunc() should set the preview option if it's set):
|
2018-07-04 07:52:08 +00:00
|
|
|
let &l:completeopt = 'menu,preview'
|
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-16 23:57:52 +00:00
|
|
|
call ale#completion#AutomaticOmniFunc(0, '')
|
2018-07-04 07:52:08 +00:00
|
|
|
|
2019-03-08 21:32:05 +00:00
|
|
|
AssertEqual 'menu,preview', b:ale_old_completeopt
|
2021-06-19 09:57:34 +00:00
|
|
|
AssertEqual 'menu,menuone,noinsert,preview', &l:completeopt
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
Execute(ale#completion#Show() should make the correct feedkeys() call for automatic completion):
|
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2018-07-26 22:08:38 +00:00
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
2018-07-17 18:39:45 +00:00
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
Execute(ale#completion#Show() should make the correct feedkeys() call for manual completion):
|
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2019-04-23 20:26:16 +00:00
|
|
|
|
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
|
|
|
|
|
|
|
|
Execute(ale#completion#Show() should not call feedkeys() for other sources):
|
2020-01-01 19:00:41 +00:00
|
|
|
let b:ale_completion_info = {'source': 'other-source'}
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2019-04-23 20:26:16 +00:00
|
|
|
|
|
|
|
sleep 1ms
|
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
|
2018-07-16 16:57:07 +00:00
|
|
|
Execute(ale#completion#Show() shouldn't do anything if you switch back to normal mode):
|
|
|
|
let &l:completeopt = 'menu,preview'
|
|
|
|
let g:fake_mode = 'n'
|
|
|
|
|
2019-05-28 19:03:35 +00:00
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2018-07-16 16:57:07 +00:00
|
|
|
|
|
|
|
AssertEqual 'menu,preview', &l:completeopt
|
|
|
|
Assert !exists('b:ale_old_omnifunc')
|
2019-03-08 21:32:05 +00:00
|
|
|
Assert !exists('b:ale_old_completeopt')
|
2019-05-28 19:03:35 +00:00
|
|
|
Assert !exists('b:ale_completion_result')
|
2018-07-16 16:57:07 +00:00
|
|
|
AssertEqual [], g:feedkeys_calls
|
|
|
|
|
2019-05-28 19:03:35 +00:00
|
|
|
Execute(ale#completion#Show() should save the result it is given):
|
|
|
|
call ale#completion#Show([])
|
|
|
|
|
|
|
|
AssertEqual [], b:ale_completion_result
|
|
|
|
|
|
|
|
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
|
2017-11-26 12:24:18 +00:00
|
|
|
|
2019-05-28 19:03:35 +00:00
|
|
|
AssertEqual [{'word': 'x', 'kind': 'v', 'icase': 1}], b:ale_completion_result
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
Execute(ale#completion#Done() should restore old omnifunc values):
|
|
|
|
let b:ale_old_omnifunc = 'FooBar'
|
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
" We reset the old omnifunc setting and remove the buffer variable.
|
|
|
|
AssertEqual 'FooBar', &l:omnifunc
|
|
|
|
Assert !has_key(b:, 'ale_old_omnifunc')
|
|
|
|
|
|
|
|
Execute(ale#completion#Done() should restore the old completeopt setting):
|
2019-03-08 21:32:05 +00:00
|
|
|
let b:ale_old_completeopt = 'menu'
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
AssertEqual 'menu', &l:completeopt
|
2019-03-08 21:32:05 +00:00
|
|
|
Assert !has_key(b:, 'ale_old_completeopt')
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
Execute(ale#completion#Done() should leave settings alone when none were remembered):
|
|
|
|
let &l:omnifunc = 'BazBoz'
|
|
|
|
let &l:completeopt = 'menu'
|
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
AssertEqual 'BazBoz', &l:omnifunc
|
|
|
|
AssertEqual 'menu', &l:completeopt
|
|
|
|
|
|
|
|
Execute(The completion request_id should be reset when queuing again):
|
|
|
|
let b:ale_completion_info = {'request_id': 123}
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
AssertEqual 0, b:ale_completion_info.request_id
|
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
Execute(b:ale_completion_info should be set up correctly when requesting completions automatically):
|
|
|
|
let b:ale_completion_result = []
|
2017-11-26 12:24:18 +00:00
|
|
|
call setpos('.', [bufnr(''), 3, 14, 0])
|
2019-04-23 20:26:16 +00:00
|
|
|
call ale#completion#GetCompletions('ale-automatic')
|
2019-03-08 21:32:05 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'request_id': 0,
|
|
|
|
\ 'conn_id': 0,
|
|
|
|
\ 'column': 14,
|
|
|
|
\ 'line_length': 14,
|
|
|
|
\ 'line': 3,
|
|
|
|
\ 'prefix': 'ab',
|
2019-04-23 20:26:16 +00:00
|
|
|
\ 'source': 'ale-automatic',
|
2019-03-08 21:32:05 +00:00
|
|
|
\ },
|
|
|
|
\ b:ale_completion_info
|
2019-04-23 20:26:16 +00:00
|
|
|
Assert !exists('b:ale_completion_result')
|
2019-03-08 21:32:05 +00:00
|
|
|
|
2019-04-23 20:26:16 +00:00
|
|
|
Execute(b:ale_completion_info should be set up correctly when requesting completions manually):
|
|
|
|
let b:ale_completion_result = []
|
2019-03-08 21:32:05 +00:00
|
|
|
call setpos('.', [bufnr(''), 3, 14, 0])
|
|
|
|
ALEComplete
|
2017-11-26 12:24:18 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'request_id': 0,
|
|
|
|
\ 'conn_id': 0,
|
|
|
|
\ 'column': 14,
|
|
|
|
\ 'line_length': 14,
|
|
|
|
\ 'line': 3,
|
|
|
|
\ 'prefix': 'ab',
|
2019-04-23 20:26:16 +00:00
|
|
|
\ 'source': 'ale-manual',
|
|
|
|
\ },
|
|
|
|
\ b:ale_completion_info
|
|
|
|
Assert !exists('b:ale_completion_result')
|
|
|
|
|
|
|
|
Execute(b:ale_completion_info should be set up correctly for other sources):
|
|
|
|
let b:ale_completion_result = []
|
|
|
|
call setpos('.', [bufnr(''), 3, 14, 0])
|
2020-01-01 19:00:41 +00:00
|
|
|
call ale#completion#GetCompletions('ale-callback')
|
2019-04-23 20:26:16 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'request_id': 0,
|
|
|
|
\ 'conn_id': 0,
|
|
|
|
\ 'column': 14,
|
|
|
|
\ 'line_length': 14,
|
|
|
|
\ 'line': 3,
|
|
|
|
\ 'prefix': 'ab',
|
2020-01-01 19:00:41 +00:00
|
|
|
\ 'source': 'ale-callback',
|
2017-11-26 12:24:18 +00:00
|
|
|
\ },
|
|
|
|
\ b:ale_completion_info
|
2019-04-23 20:26:16 +00:00
|
|
|
Assert !exists('b:ale_completion_result')
|
2018-07-17 18:39:45 +00:00
|
|
|
|
2019-08-17 17:40:05 +00:00
|
|
|
Execute(b:ale_completion_info should be set up correctly when requesting completions via callback):
|
|
|
|
let b:ale_completion_result = []
|
|
|
|
call setpos('.', [bufnr(''), 3, 14, 0])
|
|
|
|
|
|
|
|
function! CompleteCallback() abort
|
|
|
|
echo 'Called'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
call ale#completion#GetCompletions('ale-callback', {'callback': funcref('CompleteCallback')})
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'request_id': 0,
|
|
|
|
\ 'conn_id': 0,
|
|
|
|
\ 'column': 14,
|
|
|
|
\ 'line_length': 14,
|
|
|
|
\ 'line': 3,
|
|
|
|
\ 'prefix': 'ab',
|
|
|
|
\ 'source': 'ale-callback',
|
|
|
|
\ },
|
|
|
|
\ b:ale_completion_info
|
|
|
|
Assert !exists('b:ale_completion_result')
|
|
|
|
|
2018-07-17 18:39:45 +00:00
|
|
|
Execute(The correct keybinds should be configured):
|
|
|
|
redir => g:output
|
|
|
|
silent map <Plug>(ale_show_completion_menu)
|
|
|
|
redir END
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ 'n <Plug>(ale_show_completion_menu) * :call ale#completion#RestoreCompletionOptions()<CR>',
|
|
|
|
\ 'o <Plug>(ale_show_completion_menu) * <Nop>',
|
|
|
|
\ 'v <Plug>(ale_show_completion_menu) * <Nop>',
|
|
|
|
\ ],
|
|
|
|
\ sort(split(g:output, "\n"))
|
|
|
|
|
|
|
|
Execute(Running the normal mode <Plug> keybind should reset the settings):
|
|
|
|
let b:ale_old_omnifunc = 'FooBar'
|
2019-03-08 21:32:05 +00:00
|
|
|
let b:ale_old_completeopt = 'menu'
|
2018-07-17 18:39:45 +00:00
|
|
|
|
|
|
|
" We can't run the keybind, but we can call the function.
|
|
|
|
call ale#completion#RestoreCompletionOptions()
|
|
|
|
|
|
|
|
AssertEqual 'FooBar', &l:omnifunc
|
|
|
|
AssertEqual 'menu', &l:completeopt
|
|
|
|
Assert !has_key(b:, 'ale_old_omnifunc')
|
2019-03-08 21:32:05 +00:00
|
|
|
Assert !has_key(b:, 'ale_old_completeopt')
|
2019-09-12 20:53:23 +00:00
|
|
|
|
|
|
|
Execute(HandleUserData should call ale#code_action#HandleCodeAction):
|
|
|
|
let b:ale_completion_info = {'source': 'ale-manual'}
|
|
|
|
call MockHandleCodeAction()
|
|
|
|
|
|
|
|
call ale#completion#HandleUserData({})
|
|
|
|
AssertEqual g:handle_code_action_called, 0
|
|
|
|
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': ''
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 0
|
|
|
|
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({}),
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 0
|
|
|
|
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [],
|
|
|
|
\ }),
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 0
|
|
|
|
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [
|
|
|
|
\ {'description': '', 'changes': []},
|
|
|
|
\ ],
|
|
|
|
\ }),
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 1
|
|
|
|
|
|
|
|
let b:ale_completion_info = {'source': 'ale-automatic'}
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [
|
|
|
|
\ {'description': '', 'changes': []},
|
|
|
|
\ ],
|
|
|
|
\ }),
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 2
|
|
|
|
|
2019-10-18 02:47:07 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-callback'}
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [
|
|
|
|
\ {'description': '', 'changes': []},
|
|
|
|
\ ],
|
|
|
|
\ }),
|
2019-10-18 02:47:07 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 3
|
|
|
|
|
2020-09-08 20:40:10 +00:00
|
|
|
let b:ale_completion_info = {'source': 'ale-omnifunc'}
|
|
|
|
call ale#completion#HandleUserData({
|
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [
|
|
|
|
\ {'description': '', 'changes': []},
|
|
|
|
\ ],
|
|
|
|
\ }),
|
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 4
|
|
|
|
|
2019-09-12 20:53:23 +00:00
|
|
|
Execute(ale#code_action#HandleCodeAction should not be called when when source is not ALE):
|
|
|
|
call MockHandleCodeAction()
|
|
|
|
let b:ale_completion_info = {'source': 'syntastic'}
|
|
|
|
call ale#completion#HandleUserData({
|
2020-09-08 20:40:10 +00:00
|
|
|
\ 'user_data': json_encode({
|
|
|
|
\ '_ale_completion_item': 1,
|
|
|
|
\ 'code_actions': [
|
|
|
|
\ {'description': '', 'changes': []},
|
|
|
|
\ ],
|
|
|
|
\ }),
|
2019-09-12 20:53:23 +00:00
|
|
|
\})
|
|
|
|
AssertEqual g:handle_code_action_called, 0
|