mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:8.2.0925: getcompletion() does not return command line arguments
Problem: Getcompletion() does not return command line arguments.
Solution: Add the "cmdline" option. (Shougo, closes vim/vim#1140)
1f1fd44ef7
This commit is contained in:
@@ -4449,7 +4449,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
|
||||
augroup autocmd groups
|
||||
buffer buffer names
|
||||
behave :behave suboptions
|
||||
cmdline |cmdline-completion|
|
||||
cmdline |cmdline-completion| result
|
||||
color color schemes
|
||||
command Ex command (and arguments)
|
||||
compiler compilers
|
||||
@@ -4482,14 +4482,19 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
|
||||
user user names
|
||||
var user variables
|
||||
|
||||
If {pat} is an empty string then all matches are returned.
|
||||
Otherwise only items matching {pat} are returned. See
|
||||
|wildcards| for the use of special characters in {pat}.
|
||||
If {pat} is an empty string, then all the matches are
|
||||
returned. Otherwise only items matching {pat} are returned.
|
||||
See |wildcards| for the use of special characters in {pat}.
|
||||
|
||||
If the optional {filtered} flag is set to 1, then 'wildignore'
|
||||
is applied to filter the results. Otherwise all the matches
|
||||
are returned. The 'wildignorecase' option always applies.
|
||||
|
||||
If {type} is "cmdline", then the |cmdline-completion| result is
|
||||
returned. For example, to complete the possible values after
|
||||
a ":call" command: >
|
||||
echo getcompletion('call ', 'cmdline')
|
||||
<
|
||||
If there are no matches, an empty list is returned. An
|
||||
invalid value for {type} produces an error.
|
||||
|
||||
|
@@ -3134,6 +3134,12 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
|
||||
| WILD_NO_BEEP;
|
||||
|
||||
if (argvars[1].v_type != VAR_STRING) {
|
||||
EMSG2(_(e_invarg2), "type must be a string");
|
||||
return;
|
||||
}
|
||||
const char *const type = tv_get_string(&argvars[1]);
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
filtered = (bool)tv_get_number_chk(&argvars[2], NULL);
|
||||
}
|
||||
@@ -3147,12 +3153,12 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
options |= WILD_KEEP_ALL;
|
||||
}
|
||||
|
||||
if (argvars[0].v_type != VAR_STRING || argvars[1].v_type != VAR_STRING) {
|
||||
if (argvars[0].v_type != VAR_STRING) {
|
||||
EMSG(_(e_invarg));
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(tv_get_string(&argvars[1]), "cmdline") == 0) {
|
||||
if (strcmp(type, "cmdline") == 0) {
|
||||
set_one_cmd_context(&xpc, tv_get_string(&argvars[0]));
|
||||
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
|
||||
goto theend;
|
||||
@@ -3161,10 +3167,9 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
ExpandInit(&xpc);
|
||||
xpc.xp_pattern = (char_u *)tv_get_string(&argvars[0]);
|
||||
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
|
||||
xpc.xp_context = cmdcomplete_str_to_type(
|
||||
(char_u *)tv_get_string(&argvars[1]));
|
||||
xpc.xp_context = cmdcomplete_str_to_type(type);
|
||||
if (xpc.xp_context == EXPAND_NOTHING) {
|
||||
EMSG2(_(e_invarg2), argvars[1].vval.v_string);
|
||||
EMSG2(_(e_invarg2), type);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -6282,14 +6282,14 @@ int parse_compl_arg(const char_u *value, int vallen, int *complp,
|
||||
return OK;
|
||||
}
|
||||
|
||||
int cmdcomplete_str_to_type(char_u *complete_str)
|
||||
int cmdcomplete_str_to_type(const char *complete_str)
|
||||
{
|
||||
for (int i = 0; i < (int)(ARRAY_SIZE(command_complete)); i++) {
|
||||
char *cmd_compl = get_command_complete(i);
|
||||
if (cmd_compl == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (STRCMP(complete_str, command_complete[i]) == 0) {
|
||||
if (strcmp(complete_str, command_complete[i]) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@@ -442,6 +442,7 @@ func Test_getcompletion()
|
||||
set tags&
|
||||
|
||||
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
||||
call assert_fails('call getcompletion("abc", [])', 'E475:')
|
||||
endfunc
|
||||
|
||||
func Test_shellcmd_completion()
|
||||
|
Reference in New Issue
Block a user