commit 66f02ee1fea2cf3c033e48e58bd49e8b81c7a11e
parent af6b3d6fecd5f5ed741955910551db21f2e96e59
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue, 1 Jul 2025 07:58:06 +0800
vim-patch:9.1.1498: completion: 'complete' funcs behave different to 'omnifunc' (#34718)
Problem: completion: Functions specified in the 'complete' option did
not have the leader string removed when called with findstart = 0,
unlike 'omnifunc' behavior
Solution: update behaviour and make behaviour consistent (Girish Palya)
closes: vim/vim#17636
https://github.com/vim/vim/commit/fa16c7ab3f219f93b24cf31ac8aafbd6b522d1bf
Co-authored-by: Girish Palya <girishji@gmail.com>
Diffstat:
2 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
@@ -4237,17 +4237,6 @@ static Callback *get_callback_if_cpt_func(char *p)
return NULL;
}
-/// Retrieve new completion matches by invoking callback "cb".
-static void expand_cpt_function(Callback *cb)
-{
- // Re-insert the text removed by ins_compl_delete().
- ins_compl_insert_bytes(compl_orig_text.data + get_compl_len(), -1);
- // Get matches
- get_cpt_func_completion_matches(cb);
- // Undo insertion
- ins_compl_delete(false);
-}
-
/// get the next set of completion matches for "type".
/// @return true if a new match is found, otherwise false.
static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini)
@@ -4283,7 +4272,7 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_
case CTRL_X_FUNCTION:
if (ctrl_x_mode_normal()) { // Invoked by a func in 'cpt' option
- expand_cpt_function(st->func_cb);
+ get_cpt_func_completion_matches(st->func_cb, true);
} else {
expand_by_function(type, compl_pattern.data, NULL);
}
@@ -5982,7 +5971,7 @@ static compl_T *remove_old_matches(void)
/// Retrieve completion matches using the callback function "cb" and store the
/// 'refresh:always' flag.
-static void get_cpt_func_completion_matches(Callback *cb)
+static void get_cpt_func_completion_matches(Callback *cb, bool restore_leader)
{
int startcol = cpt_sources_array[cpt_sources_index].cs_startcol;
@@ -5992,7 +5981,14 @@ static void get_cpt_func_completion_matches(Callback *cb)
return;
}
+ if (restore_leader) { // Re-insert the text removed by ins_compl_delete()
+ ins_compl_insert_bytes(compl_orig_text.data + get_compl_len(), -1);
+ }
set_compl_globals(startcol, curwin->w_cursor.col, true);
+ if (restore_leader) {
+ ins_compl_delete(false); // Undo insertion
+ }
+
expand_by_function(0, cpt_compl_pattern.data, cb);
cpt_sources_array[cpt_sources_index].cs_refresh_always = compl_opt_refresh_always;
compl_opt_refresh_always = false;
@@ -6029,7 +6025,7 @@ static void cpt_compl_refresh(void)
}
cpt_sources_array[cpt_sources_index].cs_startcol = startcol;
if (ret == OK) {
- get_cpt_func_completion_matches(cb);
+ get_cpt_func_completion_matches(cb, false);
}
}
}
diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim
@@ -568,8 +568,8 @@ func Test_cpt_func_cursorcol()
call assert_equal(8, col('.'))
return col('.')
endif
- call assert_equal("foo bar", getline(1))
- call assert_equal(8, col('.'))
+ call assert_equal("foo ", getline(1))
+ call assert_equal(5, col('.'))
" return v:none
endfunc