From 0a282eb76a344f8468e47859bcbda66d0a27d86d Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 17 Aug 2017 23:06:02 +0100 Subject: [PATCH] Automatically adjust the completion options when using completion while you type --- autoload/ale/completion.vim | 10 ++++++++++ test/test_completion.vader | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index f3d74cf..07f755e 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -115,11 +115,16 @@ 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 ale#completion#FeedKeys("\\", 'n') endfunction @@ -303,6 +308,11 @@ function! ale#completion#Done() abort let &l:omnifunc = b:ale_old_omnifunc unlet b:ale_old_omnifunc endif + + if exists('b:ale_old_completopt') + let &l:completeopt = b:ale_old_completopt + unlet b:ale_old_completopt + endif endfunction function! s:Setup(enabled) abort diff --git a/test/test_completion.vader b/test/test_completion.vader index 4331dd0..8750872 100644 --- a/test/test_completion.vader +++ b/test/test_completion.vader @@ -2,6 +2,7 @@ Before: Save g:ale_completion_enabled Save g:ale_completion_delay Save &l:omnifunc + Save &l:completeopt let g:test_vars = { \ 'feedkeys_calls': [], @@ -17,6 +18,8 @@ After: Restore unlet! g:test_vars + unlet! b:ale_old_omnifunc + unlet! b:ale_old_completopt unlet! b:ale_completion_info unlet! b:ale_completion_response unlet! b:ale_completion_parser @@ -130,6 +133,14 @@ Execute(ale#completion#Show() should remember the omnifunc setting and replace i AssertEqual 'FooBar', b:ale_old_omnifunc AssertEqual 'ale#completion#OmniFunc', &l:omnifunc +Execute(ale#completion#Show() should remember the completeopt setting and replace it): + let &l:completeopt = 'menu' + + call ale#completion#Show('Response', 'Parser') + + 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') @@ -150,6 +161,24 @@ Execute(ale#completion#Done() should restore old omnifunc values): AssertEqual 'FooBar', &l:omnifunc Assert !has_key(b:, 'ale_old_omnifunc') +Execute(ale#completion#Done() should restore the old completeopt setting): + let b:ale_old_completopt = 'menu' + let &l:completeopt = 'menu,menuone,preview,noselect,noinsert' + + call ale#completion#Done() + + AssertEqual 'menu', &l:completeopt + Assert !has_key(b:, 'ale_old_completopt') + +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}