diff options
author | w0rp <devw0rp@gmail.com> | 2017-08-16 00:45:46 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-08-16 00:45:46 +0100 |
commit | 17a76a74035488112eb6df92c2a11cb0f177fec9 (patch) | |
tree | 38970b6dc9862e0d6e3da5e1e35e6c3d6c6805e5 /autoload | |
parent | 797b03b35efdb2bf30c44881b59f4c9c138e161d (diff) | |
download | ale-17a76a74035488112eb6df92c2a11cb0f177fec9.zip |
Cover completion with more tests
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/completion.vim | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index df8134a4..f3d74cf0 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -1,6 +1,10 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Completion support for LSP linters +" A do-nothing function so we can load this autoload file in tests. +function! ale#completion#Nop() abort +endfunction + let s:timer_id = -1 function! s:GetRegex(map, filetype) abort @@ -98,6 +102,11 @@ function! ale#completion#OmniFunc(findstart, base) abort endif endfunction +" A wrapper function for feedkeys so we can test calls for it. +function! ale#completion#FeedKeys(string, mode) abort + call feedkeys(a:string, a:mode) +endfunction + function! ale#completion#Show(response, completion_parser) abort " Remember the old omnifunc value, if there is one. " If we don't store an old one, we'll just never reset the option. @@ -111,7 +120,7 @@ function! ale#completion#Show(response, completion_parser) abort let b:ale_completion_response = a:response let b:ale_completion_parser = a:completion_parser let &l:omnifunc = 'ale#completion#OmniFunc' - call feedkeys("\<C-x>\<C-o>", 'n') + call ale#completion#FeedKeys("\<C-x>\<C-o>", 'n') endfunction function! s:CompletionStillValid(request_id) abort @@ -237,10 +246,6 @@ endfunction function! ale#completion#GetCompletions() abort let [l:line, l:column] = getcurpos()[1:2] - if s:timer_pos != [l:line, l:column] - return - endif - let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column) if empty(l:prefix) @@ -265,7 +270,13 @@ endfunction function! s:TimerHandler(...) abort let s:timer_id = -1 - call ale#completion#GetCompletions() + let [l:line, l:column] = getcurpos()[1:2] + + " 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. + if s:timer_pos == [l:line, l:column] + call ale#completion#GetCompletions() + endif endfunction function! ale#completion#Queue() abort |