Skip to content

Commit 982cda6

Browse files
zeertzjqchrisbra
authored andcommitted
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 <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent bc51ec5 commit 982cda6

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/insexpand.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5515,11 +5515,6 @@ ins_compl_get_exp(pos_T *ini)
55155515
}
55165516
}
55175517

5518-
// If complete() was called then compl_pattern has been reset. The
5519-
// following won't work then, bail out.
5520-
if (compl_pattern.string == NULL)
5521-
break;
5522-
55235518
if (compl_autocomplete && type == CTRL_X_FUNCTION)
55245519
// LSP servers may sporadically take >1s to respond (e.g., while
55255520
// loading modules), but other sources might already have matches.
@@ -5532,6 +5527,11 @@ ins_compl_get_exp(pos_T *ini)
55325527
// get the next set of completion matches
55335528
found_new_match = get_next_completion_match(type, &st, &start_pos);
55345529

5530+
// If complete() was called then compl_pattern has been reset. The
5531+
// following won't work then, bail out.
5532+
if (compl_pattern.string == NULL)
5533+
break;
5534+
55355535
if (may_advance_cpt_idx)
55365536
{
55375537
if (!advance_cpt_sources_index_safe())

src/testdir/test_ins_complete.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,35 @@ func Test_tagfunc_wipes_out_buffer()
32213221
bwipe!
32223222
endfunc
32233223

3224+
func s:TagfuncComplete(t,f,o)
3225+
call complete(1, ['ddd', 'eee', 'fff'])
3226+
return []
3227+
endfunc
3228+
3229+
" 'tagfunc' calling complete() should not cause hang or E684.
3230+
func Test_tagfunc_calls_complete()
3231+
new
3232+
call setline(1, ['aaa', 'bbb', 'ccc'])
3233+
setlocal tagfunc=s:TagfuncComplete
3234+
setlocal completeopt=menu,noselect
3235+
3236+
let v:errmsg = ''
3237+
3238+
" This used to hang.
3239+
setlocal complete=.,t
3240+
call feedkeys("Go\<C-N>\<C-E>\<Esc>", 'tx')
3241+
call assert_equal('', getline('.'))
3242+
call assert_equal('', v:errmsg)
3243+
3244+
" This used to cause E684.
3245+
setlocal complete=t,.
3246+
call feedkeys("cc\<C-N>\<C-E>\<Esc>", 'tx')
3247+
call assert_equal('', getline('.'))
3248+
call assert_equal('', v:errmsg)
3249+
3250+
bwipe!
3251+
endfunc
3252+
32243253
func Test_ins_complete_popup_position()
32253254
CheckScreendump
32263255

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1610,
722724
/**/
723725
1609,
724726
/**/

0 commit comments

Comments
 (0)