diff options
author | w0rp <devw0rp@gmail.com> | 2018-07-26 23:08:38 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2018-07-26 23:08:38 +0100 |
commit | daab1a08db7bc0436186751456ebd5b9a32c24f9 (patch) | |
tree | 901ff85d41d1a3288a2d84bba7b839d4b6d238b0 | |
parent | f8e61ff90797e37b3af8ab98435528abb7e3ed83 (diff) | |
download | ale-daab1a08db7bc0436186751456ebd5b9a32c24f9.zip |
#1700 - Try using a 0ms timer showing the completion menu
-rw-r--r-- | autoload/ale/completion.vim | 14 | ||||
-rw-r--r-- | test/completion/test_completion_events.vader | 20 |
2 files changed, 19 insertions, 15 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index c79ac634..900d1871 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -1,17 +1,10 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Completion support for LSP linters -function! ale#completion#TriggerOmnicompleteMenu() abort - " Replace completion options shortly before opening the menu. - call s:ReplaceCompletionOptions() - - return "\<C-x>\<C-o>" -endfunction - " The omnicompletion menu is shown through a special Plug mapping which is " only valid in Insert mode. This way, feedkeys() won't send these keys if you " quit Insert mode quickly enough. -inoremap <silent> <Plug>(ale_show_completion_menu) <C-R>=ale#completion#TriggerOmnicompleteMenu()<CR> +inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o> " If we hit the key sequence in normal mode, then we won't show the menu, so " we should restore the old settings right away. nnoremap <silent> <Plug>(ale_show_completion_menu) :call ale#completion#RestoreCompletionOptions()<CR> @@ -221,7 +214,10 @@ function! ale#completion#Show(response, completion_parser) abort " function, and then start omni-completion. let b:ale_completion_response = a:response let b:ale_completion_parser = a:completion_parser - call ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)") + " Replace completion options shortly before opening the menu. + call s:ReplaceCompletionOptions() + + call timer_start(0, {-> ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")}) endfunction function! s:CompletionStillValid(request_id) abort diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index dfffab61..3f0bfa70 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -125,32 +125,38 @@ Execute(ale#completion#Show() should remember the omnifunc setting and replace i let &l:omnifunc = 'FooBar' call ale#completion#Show('Response', 'Parser') - AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls - call ale#completion#TriggerOmnicompleteMenu() AssertEqual 'FooBar', b:ale_old_omnifunc AssertEqual 'ale#completion#OmniFunc', &l:omnifunc + AssertEqual [], g:feedkeys_calls + sleep 1ms + AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls + Execute(ale#completion#Show() should remember the completeopt setting and replace it): let &l:completeopt = 'menu' call ale#completion#Show('Response', 'Parser') - AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls - call ale#completion#TriggerOmnicompleteMenu() AssertEqual 'menu', b:ale_old_completopt AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt + AssertEqual [], g:feedkeys_calls + sleep 1ms + AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls + Execute(ale#completion#Show() should set the preview option if it's set): let &l:completeopt = 'menu,preview' call ale#completion#Show('Response', 'Parser') - AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls - call ale#completion#TriggerOmnicompleteMenu() AssertEqual 'menu,preview', b:ale_old_completopt 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#OmniFunc() should also remember the completeopt setting and replace it): let &l:completeopt = 'menu' @@ -170,6 +176,8 @@ Execute(ale#completion#OmniFunc() should set the preview option if it's set): Execute(ale#completion#Show() should make the correct feedkeys() call): call ale#completion#Show('Response', 'Parser') + AssertEqual [], g:feedkeys_calls + sleep 1ms AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls Execute(ale#completion#Show() shouldn't do anything if you switch back to normal mode): |