diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 89bf34fcc9..89fae92c86 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -4608,12 +4608,6 @@ static int 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.data == 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. @@ -4627,6 +4621,12 @@ static int 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.data == NULL) { + break; + } + if (may_advance_cpt_idx) { if (!advance_cpt_sources_index_safe()) { break; diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index 573441e6e3..7c08eb13fb 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -3290,6 +3290,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\\\", 'tx') + call assert_equal('', getline('.')) + call assert_equal('', v:errmsg) + + " This used to cause E684. + setlocal complete=t,. + call feedkeys("cc\\\", 'tx') + call assert_equal('', getline('.')) + call assert_equal('', v:errmsg) + + bwipe! +endfunc + func Test_ins_complete_popup_position() CheckScreendump