patch 9.1.1610: completion: hang or E684 when 'tagfunc' calls complete()
Commit:
https://github.com/vim/vim/commit/982cda69764ac0575125bc8786177e48f5fd9420
Author: zeertzjq <[email protected]>
Date: Fri Aug 8 16:03:43 2025 +0200
patch 9.1.1610: completion: hang or E684 when 'tagfunc' calls complete()
Problem: completion: hang (after 9.1.1471) or E684 (after 9.1.1410)
when 'tagfunc' calls complete().
Solution: Check if complete() has been called immediately after getting
matches instead of in the next loop iteration (zeertzjq).
related: #1668
related: neovim/neovim#34416
related: neovim/neovim#35163
closes: #17929
Signed-off-by: zeertzjq <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/insexpand.c b/src/insexpand.c
index 5b4afb9e4..3a775422d 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -5515,11 +5515,6 @@ ins_compl_get_exp(pos_T *ini)
}
}
- // If complete() was called then compl_pattern has been reset. The
- // following won't work then, bail out.
- if (compl_pattern.string == NULL)
- break;
-
if (compl_autocomplete && type == CTRL_X_FUNCTION)
// LSP servers may sporadically take >1s to respond (e.g., while
// loading modules), but other sources might already have matches.
@@ -5532,6 +5527,11 @@ ins_compl_get_exp(pos_T *ini)
// get the next set of completion matches
found_new_match = get_next_completion_match(type, &st, &start_pos);
+ // If complete() was called then compl_pattern has been reset. The
+ // following won't work then, bail out.
+ if (compl_pattern.string == NULL)
+ break;
+
if (may_advance_cpt_idx)
{
if (!advance_cpt_sources_index_safe())
diff --git a/src/testdir/test_ins_complete.vim
b/src/testdir/test_ins_complete.vim
index 560b2c424..1ec71118c 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -3221,6 +3221,35 @@ func Test_tagfunc_wipes_out_buffer()
bwipe!
endfunc
+func s:TagfuncComplete(t,f,o)
+ call complete(1, ['ddd', 'eee', 'fff'])
+ return []
+endfunc
+
+" 'tagfunc' calling complete() should not cause hang or E684.
+func Test_tagfunc_calls_complete()
+ new
+ call setline(1, ['aaa', 'bbb', 'ccc'])
+ setlocal tagfunc=s:TagfuncComplete
+ setlocal completeopt=menu,noselect
+
+ let v:errmsg = ''
+
+ " This used to hang.
+ setlocal complete=.,t
+ call feedkeys("Go\<C-N>\<C-E>\<Esc>", 'tx')
+ call assert_equal('', getline('.'))
+ call assert_equal('', v:errmsg)
+
+ " This used to cause E684.
+ setlocal complete=t,.
+ call feedkeys("cc\<C-N>\<C-E>\<Esc>", 'tx')
+ call assert_equal('', getline('.'))
+ call assert_equal('', v:errmsg)
+
+ bwipe!
+endfunc
+
func Test_ins_complete_popup_position()
CheckScreendump
diff --git a/src/version.c b/src/version.c
index 4abf6025d..e2c46855e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1610,
/**/
1609,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1ukNs8-002Z6I-6E%40256bit.org.