mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 00:18:33 +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:
@@ -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