summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-17 23:06:02 +0100
committerw0rp <devw0rp@gmail.com>2017-08-17 23:06:02 +0100
commit0a282eb76a344f8468e47859bcbda66d0a27d86d (patch)
treebd53b10b5f7de57dcd48cba3bcdb4373ae29e4cc
parent342e83db60dd929cbef1d00e1864e607760ca9bb (diff)
downloadale-0a282eb76a344f8468e47859bcbda66d0a27d86d.zip
Automatically adjust the completion options when using completion while you type
-rw-r--r--autoload/ale/completion.vim10
-rw-r--r--test/test_completion.vader29
2 files changed, 39 insertions, 0 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index f3d74cf0..07f755ea 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("\<C-x>\<C-o>", '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 4331dd0d..8750872e 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}