]> granicus.if.org Git - vim/commitdiff
patch 8.2.3638: getcompletion() always passes zero as position v8.2.3638
authorii14 <ii14@users.noreply.github.com>
Sun, 21 Nov 2021 12:13:56 +0000 (12:13 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 21 Nov 2021 12:13:56 +0000 (12:13 +0000)
Problem:    getcompletion() always passes zero as position to custom
            completion function.
Solution:   Pass the pattern length. (closes #9173)

src/cmdexpand.c
src/testdir/test_cmdline.vim
src/version.c

index 71c4f690cb842633172e9f8c3b6b4d0fa610da30..9e88d99b7abe849034105f29f2d86e76329fa9c9 100644 (file)
@@ -2900,6 +2900,7 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
                || check_for_opt_bool_arg(argvars, 2) == FAIL))
        return;
 
+    pat = tv_get_string(&argvars[0]);
     if (argvars[1].v_type != VAR_STRING)
     {
        semsg(_(e_invarg2), "type must be a string");
@@ -2920,12 +2921,13 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
     ExpandInit(&xpc);
     if (STRCMP(type, "cmdline") == 0)
     {
-       set_one_cmd_context(&xpc, tv_get_string(&argvars[0]));
+       set_one_cmd_context(&xpc, pat);
        xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
+       xpc.xp_col = (int)STRLEN(pat);
     }
     else
     {
-       xpc.xp_pattern = tv_get_string(&argvars[0]);
+       xpc.xp_pattern = pat;
        xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
 
        xpc.xp_context = cmdcomplete_str_to_type(type);
index 295e59db2f0e4d01e3882306fd3b580df7f28331..abd12467dd676a92ef39d23fb928b16ab5eabf00 100644 (file)
@@ -424,14 +424,17 @@ func Test_getcompletion()
   call assert_equal([], l)
 
   func T(a, c, p)
+    let g:cmdline_compl_params = [a:a, a:c, a:p]
     return "oneA\noneB\noneC"
   endfunc
   command -nargs=1 -complete=custom,T MyCmd
   let l = getcompletion('MyCmd ', 'cmdline')
   call assert_equal(['oneA', 'oneB', 'oneC'], l)
+  call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
 
   delcommand MyCmd
   delfunc T
+  unlet g:cmdline_compl_params
 
   " For others test if the name is recognized.
   let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
index f508d77826b09224189d060cfa9db39d3cc49b17..76cc5a47d849681928acbc56136a0aba4cb077e5 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3638,
 /**/
     3637,
 /**/