]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0498: getcmdcompltype() interferes with cmdline completion v9.1.0498
authorzeertzjq <zeertzjq@outlook.com>
Tue, 18 Jun 2024 18:31:08 +0000 (20:31 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 18 Jun 2024 18:31:08 +0000 (20:31 +0200)
Problem:  getcmdcompltype() interferes with cmdline completion.
Solution: Don't set expand context when it's already set.
          (zeertzjq)

closes: #15036

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/ex_getln.c
src/testdir/test_cmdline.vim
src/version.c

index 3ae4958f8e67d7a78992766ae32e70c90293184c..3444a0e86e695faaf97a2fdaeb4f6242ca0a5b8d 100644 (file)
@@ -4176,6 +4176,7 @@ get_cmdline_completion(void)
 {
     cmdline_info_T *p;
     char_u     *buffer;
+    int                xp_context;
 
     if (cmdline_star > 0)
        return NULL;
@@ -4184,15 +4185,21 @@ get_cmdline_completion(void)
     if (p == NULL || p->xpc == NULL)
        return NULL;
 
-    set_expand_context(p->xpc);
-    if (p->xpc->xp_context == EXPAND_UNSUCCESSFUL)
+    xp_context = p->xpc->xp_context;
+    if (xp_context == EXPAND_NOTHING)
+    {
+       set_expand_context(p->xpc);
+       xp_context = p->xpc->xp_context;
+       p->xpc->xp_context = EXPAND_NOTHING;
+    }
+    if (xp_context == EXPAND_UNSUCCESSFUL)
        return NULL;
 
-    char_u *cmd_compl = cmdcomplete_type_to_str(p->xpc->xp_context);
+    char_u *cmd_compl = cmdcomplete_type_to_str(xp_context);
     if (cmd_compl == NULL)
        return NULL;
 
-    if (p->xpc->xp_context == EXPAND_USER_LIST || p->xpc->xp_context == EXPAND_USER_DEFINED)
+    if (xp_context == EXPAND_USER_LIST || xp_context == EXPAND_USER_DEFINED)
     {
        buffer = alloc(STRLEN(cmd_compl) + STRLEN(p->xpc->xp_arg) + 2);
        if (buffer == NULL)
index 8b7489ea46a1d63d150eda6c8cf728130cf4f4ec..8651a9dbba4a274e324bf1d2bde9432b1f9592e5 100644 (file)
@@ -3612,7 +3612,7 @@ func Test_cmdline_complete_bang_cmd_argument()
 endfunc
 
 func Call_cmd_funcs()
-  return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
+  return [getcmdpos(), getcmdscreenpos(), getcmdcompltype()]
 endfunc
 
 func Test_screenpos_and_completion()
@@ -3620,13 +3620,24 @@ func Test_screenpos_and_completion()
   call assert_equal(0, getcmdscreenpos())
   call assert_equal('', getcmdcompltype())
 
-  cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
+  cnoremap <expr> <F2> string(Call_cmd_funcs())
   call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
   call assert_equal("\"let a[6, 7, 'var']", @:)
   call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
   call assert_equal("\"quit [6, 7, '']", @:)
   call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
   call assert_equal("\"nosuchcommand [15, 16, '']", @:)
+
+  " Check that getcmdcompltype() doesn't interfere with cmdline completion.
+  let g:results = []
+  cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
+  call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
+  call assert_equal([
+        \ ['sign undefine', 14, 15, 'sign'],
+        \ ['sign unplace', 13, 14, 'sign'],
+        \ ['sign un', 8, 9, 'sign']], g:results)
+
+  unlet g:results
   cunmap <F2>
 endfunc
 
index 81741047688f6bfab5711e0c4ddcb4582f6b3fe4..7f84d9dfde7baa9978564422930dbf441af73479 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    498,
 /**/
     497,
 /**/