patch 9.1.0774: "shellcmdline" doesn't work with getcompletion()
Problem: "shellcmdline" doesn't work with getcompletion().
Solution: Use set_context_for_wildcard_arg() (zeertzjq).
closes: #15834
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index e563d22..3f74f47 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -1721,7 +1721,7 @@
// characters that end the command and white space.
else if (c == '|' || c == '\n' || c == '"' || (VIM_ISWHITE(c)
#ifdef SPACE_IN_FILENAME
- && (!(eap->argt & EX_NOSPC) || usefilter)
+ && (!(eap != NULL && (eap->argt & EX_NOSPC)) || usefilter)
#endif
))
{
@@ -1756,7 +1756,10 @@
xp->xp_context = EXPAND_FILES;
// For a shell command more chars need to be escaped.
- if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal || *complp == EXPAND_SHELLCMDLINE)
+ if (usefilter
+ || (eap != NULL
+ && (eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal))
+ || *complp == EXPAND_SHELLCMDLINE)
{
#ifndef BACKSLASH_IN_FILENAME
xp->xp_shell = TRUE;
@@ -4208,6 +4211,13 @@
set_context_in_runtime_cmd(&xpc, xpc.xp_pattern);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
}
+ if (xpc.xp_context == EXPAND_SHELLCMDLINE)
+ {
+ int context = EXPAND_SHELLCMDLINE;
+ set_context_for_wildcard_arg(NULL, xpc.xp_pattern, FALSE, &xpc,
+ &context);
+ xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
+ }
}
if (cmdline_fuzzy_completion_supported(&xpc))
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 418dafa..e1dbc87 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -1084,6 +1084,8 @@
call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_match('^".*\<whoami\>', @:)
+ let l = getcompletion('whoam', 'shellcmdline')
+ call assert_match('\<whoami\>', join(l, ' '))
delcommand MyCmd
endfunc
@@ -3649,9 +3651,13 @@
call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"MyCmd vim test_cmdline.vim', @:)
+ call assert_equal(['test_cmdline.vim'],
+ \ getcompletion('vim test_cmdline.', 'shellcmdline'))
call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"MyCmd vim nonexistentfile', @:)
+ call assert_equal([],
+ \ getcompletion('vim nonexistentfile', 'shellcmdline'))
let compl1 = getcompletion('', 'file')[0]
let compl2 = getcompletion('', 'file')[1]
@@ -3668,9 +3674,13 @@
set wildoptions&
call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"MyCmd vim test_cmdline.vim', @:)
+ call assert_equal(['test_cmdline.vim'],
+ \ getcompletion('vim test_cmdline.', 'shellcmdline'))
call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"MyCmd vim nonexistentfile', @:)
+ call assert_equal([],
+ \ getcompletion('vim nonexistentfile', 'shellcmdline'))
let compl1 = getcompletion('', 'file')[0]
let compl2 = getcompletion('', 'file')[1]
diff --git a/src/version.c b/src/version.c
index 905daf9..aa53d0a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 774,
+/**/
773,
/**/
772,