]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1498: completion: 'complete' funcs behave different to 'omnifunc' v9.1.1498
authorGirish Palya <girishji@gmail.com>
Mon, 30 Jun 2025 18:14:43 +0000 (20:14 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 30 Jun 2025 18:18:14 +0000 (20:18 +0200)
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: #17636

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index ed1b5ff292914232699e6268b4125faf8e02b8a4..0c920709e409d8ec77ebbf9e7ab603e10fd1a0d5 100644 (file)
@@ -250,7 +250,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
 static void ins_compl_add_list(list_T *list);
 static void ins_compl_add_dict(dict_T *dict);
 static int get_userdefined_compl_info(colnr_T curs_col, callback_T *cb, int *startcol);
-static void get_cpt_func_completion_matches(callback_T *cb);
+static void get_cpt_func_completion_matches(callback_T *cb, int restore_leader);
 static callback_T *get_callback_if_cpt_func(char_u *p);
 # endif
 static int setup_cpt_sources(void);
@@ -4807,20 +4807,6 @@ get_callback_if_cpt_func(char_u *p)
     }
     return NULL;
 }
-
-/*
- * Retrieve new completion matches by invoking callback "cb".
- */
-    static void
-expand_cpt_function(callback_T *cb)
-{
-    // Re-insert the text removed by ins_compl_delete().
-    ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
-    // Get matches
-    get_cpt_func_completion_matches(cb);
-    // Undo insertion
-    ins_compl_delete();
-}
 #endif
 
 /*
@@ -4984,7 +4970,7 @@ get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini)
 #ifdef FEAT_COMPL_FUNC
        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.string, NULL);
            break;
@@ -6989,16 +6975,23 @@ remove_old_matches(void)
  */
 #ifdef FEAT_COMPL_FUNC
     static void
-get_cpt_func_completion_matches(callback_T *cb UNUSED)
+get_cpt_func_completion_matches(callback_T *cb UNUSED, int restore_leader)
 {
     int        startcol = cpt_sources_array[cpt_sources_index].cs_startcol;
+    int        result;
 
     VIM_CLEAR_STRING(cpt_compl_pattern);
 
     if (startcol == -2 || startcol == -3)
        return;
 
-    if (set_compl_globals(startcol, curwin->w_cursor.col, TRUE) == OK)
+    if (restore_leader) // Re-insert the text removed by ins_compl_delete()
+       ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
+    result = set_compl_globals(startcol, curwin->w_cursor.col, TRUE);
+    if (restore_leader)
+       ins_compl_delete(); // Undo insertion
+
+    if (result == OK)
     {
        expand_by_function(0, cpt_compl_pattern.string, cb);
        cpt_sources_array[cpt_sources_index].cs_refresh_always =
@@ -7051,7 +7044,7 @@ 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);
            }
        }
 
index b6692b55423c7c15363eccda56aaaaaa05870fb9..d7309cb5413be626bcde2c80578956787c08cb87 100644 (file)
@@ -592,8 +592,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
 
index 7b13da4dab637c64f3f9da28088353e3748ced1a..23a9f19aac13e808da19a4b3e9ac77fb6ccb4ba5 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1498,
 /**/
     1497,
 /**/