diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-01-17 23:31:18 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-01-17 23:46:00 -0500 |
commit | ad35cbca76222deb33357b63a61a29945ef084f7 (patch) | |
tree | 8106670804b58724a15c64da4473b78393528601 | |
parent | 3d0c3148fbc3b66636bb9627db64331365ac1732 (diff) | |
download | rneovim-ad35cbca76222deb33357b63a61a29945ef084f7.tar.gz rneovim-ad35cbca76222deb33357b63a61a29945ef084f7.tar.bz2 rneovim-ad35cbca76222deb33357b63a61a29945ef084f7.zip |
vim-patch:8.2.0123: complete_info() does not work when CompleteDone is triggered
Problem: complete_info() does not work when CompleteDone is triggered.
Solution: Trigger CompleteDone before clearing the info.
https://github.com/vim/vim/commit/17e04781f26c24769e202351c194ee252927eee1
-rw-r--r-- | runtime/doc/autocmd.txt | 2 | ||||
-rw-r--r-- | src/nvim/edit.c | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_ins_complete.vim | 2 |
3 files changed, 17 insertions, 3 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 45bead968d..774e6a5d92 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -596,6 +596,8 @@ CompleteChanged *CompleteChanged* CompleteDone After Insert mode completion is done. Either when something was completed or abandoning completion. |ins-completion| + |complete_info()| can be used, the info is + cleared after triggering CompleteDone. The |v:completed_item| variable contains the completed item. diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 9bc00cf2aa..0c183add16 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3385,6 +3385,7 @@ static bool ins_compl_prep(int c) { char_u *ptr; bool retval = false; + const int prev_mode = ctrl_x_mode; /* Forget any previous 'special' messages if this is actually * a ^X mode key - bar ^R, in which case we wait to see what it gives us. @@ -3593,6 +3594,18 @@ static bool ins_compl_prep(int c) auto_format(FALSE, TRUE); + { + const int new_mode = ctrl_x_mode; + + // Trigger the CompleteDone event to give scripts a chance to + // act upon the completion. Do this before clearing the info, + // and restore ctrl_x_mode, so that complete_info() can be + // used. + ctrl_x_mode = prev_mode; + ins_apply_autocmds(EVENT_COMPLETEDONE); + ctrl_x_mode = new_mode; + } + ins_compl_free(); compl_started = false; compl_matches = 0; @@ -3617,9 +3630,6 @@ static bool ins_compl_prep(int c) */ if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0))) do_c_expr_indent(); - /* Trigger the CompleteDone event to give scripts a chance to act - * upon the completion. */ - ins_apply_autocmds(EVENT_COMPLETEDONE); } } else if (ctrl_x_mode == CTRL_X_LOCAL_MSG) /* Trigger the CompleteDone event to give scripts a chance to act diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 4140d16a4c..e6d427db05 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -138,6 +138,8 @@ function! s:CompleteDone_CheckCompletedItemDict() call assert_equal( 'W', v:completed_item[ 'kind' ] ) call assert_equal( 'test', v:completed_item[ 'user_data' ] ) + call assert_equal('function', complete_info().mode) + let s:called_completedone = 1 endfunction |