forked from aniani/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 #1140)
This commit is contained in:
@@ -5112,6 +5112,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
|
|||||||
behave :behave suboptions
|
behave :behave suboptions
|
||||||
color color schemes
|
color color schemes
|
||||||
command Ex command (and arguments)
|
command Ex command (and arguments)
|
||||||
|
cmdline |cmdline-completion| result
|
||||||
compiler compilers
|
compiler compilers
|
||||||
cscope |:cscope| suboptions
|
cscope |:cscope| suboptions
|
||||||
diff_buffer |:diffget| and |:diffput| completion
|
diff_buffer |:diffget| and |:diffput| completion
|
||||||
@@ -5142,14 +5143,19 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
|
|||||||
user user names
|
user user names
|
||||||
var user variables
|
var user variables
|
||||||
|
|
||||||
If {pat} is an empty string, then all the matches are returned.
|
If {pat} is an empty string, then all the matches are
|
||||||
Otherwise only items matching {pat} are returned. See
|
returned. Otherwise only items matching {pat} are returned.
|
||||||
|wildcards| for the use of special characters in {pat}.
|
See |wildcards| for the use of special characters in {pat}.
|
||||||
|
|
||||||
If the optional {filtered} flag is set to 1, then 'wildignore'
|
If the optional {filtered} flag is set to 1, then 'wildignore'
|
||||||
is applied to filter the results. Otherwise all the matches
|
is applied to filter the results. Otherwise all the matches
|
||||||
are returned. The 'wildignorecase' option always applies.
|
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
|
If there are no matches, an empty list is returned. An
|
||||||
invalid value for {type} produces an error.
|
invalid value for {type} produces an error.
|
||||||
|
|
||||||
|
@@ -2675,10 +2675,18 @@ globpath(
|
|||||||
f_getcompletion(typval_T *argvars, typval_T *rettv)
|
f_getcompletion(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
char_u *pat;
|
char_u *pat;
|
||||||
|
char_u *type;
|
||||||
expand_T xpc;
|
expand_T xpc;
|
||||||
int filtered = FALSE;
|
int filtered = FALSE;
|
||||||
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
|
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
|
||||||
| WILD_NO_BEEP;
|
| WILD_NO_BEEP;
|
||||||
|
|
||||||
|
if (argvars[1].v_type != VAR_STRING)
|
||||||
|
{
|
||||||
|
semsg(_(e_invarg2), "type must be a string");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
type = tv_get_string(&argvars[1]);
|
||||||
|
|
||||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||||
filtered = tv_get_number_chk(&argvars[2], NULL);
|
filtered = tv_get_number_chk(&argvars[2], NULL);
|
||||||
@@ -2691,39 +2699,45 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
|
|||||||
options |= WILD_KEEP_ALL;
|
options |= WILD_KEEP_ALL;
|
||||||
|
|
||||||
ExpandInit(&xpc);
|
ExpandInit(&xpc);
|
||||||
xpc.xp_pattern = tv_get_string(&argvars[0]);
|
if (STRCMP(type, "cmdline") == 0)
|
||||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
|
||||||
xpc.xp_context = cmdcomplete_str_to_type(tv_get_string(&argvars[1]));
|
|
||||||
if (xpc.xp_context == EXPAND_NOTHING)
|
|
||||||
{
|
{
|
||||||
if (argvars[1].v_type == VAR_STRING)
|
set_one_cmd_context(&xpc, tv_get_string(&argvars[0]));
|
||||||
semsg(_(e_invarg2), argvars[1].vval.v_string);
|
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||||
else
|
|
||||||
emsg(_(e_invarg));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xpc.xp_pattern = tv_get_string(&argvars[0]);
|
||||||
|
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||||
|
|
||||||
|
xpc.xp_context = cmdcomplete_str_to_type(type);
|
||||||
|
if (xpc.xp_context == EXPAND_NOTHING)
|
||||||
|
{
|
||||||
|
semsg(_(e_invarg2), type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# if defined(FEAT_MENU)
|
# if defined(FEAT_MENU)
|
||||||
if (xpc.xp_context == EXPAND_MENUS)
|
if (xpc.xp_context == EXPAND_MENUS)
|
||||||
{
|
{
|
||||||
set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE);
|
set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE);
|
||||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
# ifdef FEAT_CSCOPE
|
# ifdef FEAT_CSCOPE
|
||||||
if (xpc.xp_context == EXPAND_CSCOPE)
|
if (xpc.xp_context == EXPAND_CSCOPE)
|
||||||
{
|
{
|
||||||
set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope);
|
set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope);
|
||||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
# ifdef FEAT_SIGNS
|
# ifdef FEAT_SIGNS
|
||||||
if (xpc.xp_context == EXPAND_SIGN)
|
if (xpc.xp_context == EXPAND_SIGN)
|
||||||
{
|
{
|
||||||
set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
|
set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
|
||||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
|
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
|
||||||
if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
|
if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
|
||||||
|
@@ -355,6 +355,20 @@ func Test_getcompletion()
|
|||||||
call assert_equal(['Testing'], l)
|
call assert_equal(['Testing'], l)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Command line completion tests
|
||||||
|
let l = getcompletion('cd ', 'cmdline')
|
||||||
|
call assert_true(index(l, 'samples/') >= 0)
|
||||||
|
let l = getcompletion('cd NoMatch', 'cmdline')
|
||||||
|
call assert_equal([], l)
|
||||||
|
let l = getcompletion('let v:n', 'cmdline')
|
||||||
|
call assert_true(index(l, 'v:null') >= 0)
|
||||||
|
let l = getcompletion('let v:notexists', 'cmdline')
|
||||||
|
call assert_equal([], l)
|
||||||
|
let l = getcompletion('call tag', 'cmdline')
|
||||||
|
call assert_true(index(l, 'taglist(') >= 0)
|
||||||
|
let l = getcompletion('call paint', 'cmdline')
|
||||||
|
call assert_equal([], l)
|
||||||
|
|
||||||
" For others test if the name is recognized.
|
" For others test if the name is recognized.
|
||||||
let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
|
let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
|
||||||
if has('cmdline_hist')
|
if has('cmdline_hist')
|
||||||
@@ -379,7 +393,7 @@ func Test_getcompletion()
|
|||||||
set tags&
|
set tags&
|
||||||
|
|
||||||
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
||||||
call assert_fails('call getcompletion("abc", [])', 'E474:')
|
call assert_fails('call getcompletion("abc", [])', 'E475:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_shellcmd_completion()
|
func Test_shellcmd_completion()
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
925,
|
||||||
/**/
|
/**/
|
||||||
924,
|
924,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user