Fix #1041 - Do not request completions shortly after CompleteDone

This commit is contained in:
w0rp 2017-10-26 23:18:12 +01:00
parent 33c2c20e66
commit 6490d3a5e6
2 changed files with 34 additions and 12 deletions

View File

@ -283,6 +283,13 @@ function! s:TimerHandler(...) abort
endfunction endfunction
function! ale#completion#Queue() abort function! ale#completion#Queue() abort
let l:time = get(b:, 'ale_complete_done_time', 0)
if l:time && ale#util#ClockMilliseconds() - l:time < 100
" Do not ask for completions shortly after we just closed the menu.
return
endif
let s:timer_pos = getcurpos()[1:2] let s:timer_pos = getcurpos()[1:2]
" If we changed the text again while we're still waiting for a response, " If we changed the text again while we're still waiting for a response,
@ -311,6 +318,9 @@ function! ale#completion#Done() abort
let &l:completeopt = b:ale_old_completopt let &l:completeopt = b:ale_old_completopt
unlet b:ale_old_completopt unlet b:ale_old_completopt
endif endif
" Set a timestamp, so we can avoid requesting completions again.
let b:ale_complete_done_time = ale#util#ClockMilliseconds()
endfunction endfunction
function! s:Setup(enabled) abort function! s:Setup(enabled) abort

View File

@ -13,6 +13,21 @@ Before:
call add(g:test_vars.feedkeys_calls, [a:string, a:mode]) call add(g:test_vars.feedkeys_calls, [a:string, a:mode])
endfunction endfunction
function! CheckCompletionCalled(expect_success) abort
let g:test_vars.get_completions_called = 0
" We just want to check if the function is called.
function! ale#completion#GetCompletions()
let g:test_vars.get_completions_called = 1
endfunction
let g:ale_completion_delay = 0
call ale#completion#Queue()
sleep 1m
AssertEqual a:expect_success, g:test_vars.get_completions_called
endfunction
After: After:
Restore Restore
@ -22,6 +37,9 @@ After:
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
unlet! b:ale_complete_done_time
delfunction CheckCompletionCalled
runtime autoload/ale/completion.vim runtime autoload/ale/completion.vim
runtime autoload/ale/lsp.vim runtime autoload/ale/lsp.vim
@ -294,18 +312,7 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
\ b:ale_completion_info \ b:ale_completion_info
Execute(ale#completion#GetCompletions should be called when the cursor position stays the same): Execute(ale#completion#GetCompletions should be called when the cursor position stays the same):
let g:test_vars.get_completions_called = 0 call CheckCompletionCalled(1)
" We just want to check if the function is called.
function! ale#completion#GetCompletions()
let g:test_vars.get_completions_called = 1
endfunction
let g:ale_completion_delay = 0
call ale#completion#Queue()
sleep 1m
Assert g:test_vars.get_completions_called
Execute(ale#completion#GetCompletions should not be called when the cursor position changes): Execute(ale#completion#GetCompletions should not be called when the cursor position changes):
call setpos('.', [bufnr(''), 1, 2, 0]) call setpos('.', [bufnr(''), 1, 2, 0])
@ -326,3 +333,8 @@ Execute(ale#completion#GetCompletions should not be called when the cursor posit
sleep 1m sleep 1m
Assert !g:test_vars.get_completions_called Assert !g:test_vars.get_completions_called
Execute(Completion should not be done shortly after the CompleteDone function):
call CheckCompletionCalled(1)
call ale#completion#Done()
call CheckCompletionCalled(0)