diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index 07f755ea..3bcf3e9f 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -71,6 +71,14 @@ function! ale#completion#FilterSuggestionsByPrefix(suggestions, prefix) abort return l:filtered_suggestions endfunction +function! s:ReplaceCompleteopt() abort + if !exists('b:ale_old_completopt') + let b:ale_old_completopt = &l:completeopt + endif + + let &l:completeopt = 'menu,menuone,preview,noselect,noinsert' +endfunction + function! ale#completion#OmniFunc(findstart, base) abort if a:findstart let l:line = b:ale_completion_info.line @@ -98,6 +106,8 @@ function! ale#completion#OmniFunc(findstart, base) abort \)[: g:ale_completion_max_suggestions] endif + call s:ReplaceCompleteopt() + return get(b:, 'ale_completion_result', []) endif endfunction @@ -115,16 +125,12 @@ function! ale#completion#Show(response, completion_parser) abort let b:ale_old_omnifunc = &l:omnifunc endif - if !exists('b:ale_old_completopt') - let b:ale_old_completopt = &l:completeopt - endif - " Set the list in the buffer, temporarily replace omnifunc with our " function, and then start omni-completion. let b:ale_completion_response = a:response let b:ale_completion_parser = a:completion_parser let &l:omnifunc = 'ale#completion#OmniFunc' - let &l:completeopt = 'menu,menuone,preview,noselect,noinsert' + call s:ReplaceCompleteopt() call ale#completion#FeedKeys("\\", 'n') endfunction diff --git a/test/test_completion.vader b/test/test_completion.vader index 8750872e..245f8db8 100644 --- a/test/test_completion.vader +++ b/test/test_completion.vader @@ -141,6 +141,14 @@ Execute(ale#completion#Show() should remember the completeopt setting and replac AssertEqual 'menu', b:ale_old_completopt AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt +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,menuone,preview,noselect,noinsert', &l:completeopt + Execute(ale#completion#Show() should make the correct feedkeys() call): call ale#completion#Show('Response', 'Parser')