vim-patch:8.2.2341: expresison command line completion incomplete after "g:"

Problem:    Expresison command line completion shows variables but not
            functions after "g:". (Gary Johnson)
Solution:   Prefix "g:" when needed to a global function.
1bb4de5302

Port most of patch v8.2.0335 to complete script-local functions
if the name starts with "s:".
This commit is contained in:
Jan Edmund Lazo 2021-03-12 22:56:58 -05:00
parent b650d2d8d9
commit a4ea602788
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
4 changed files with 35 additions and 2 deletions

View File

@ -3007,7 +3007,8 @@ static size_t varnamebuflen = 0;
/*
* Function to concatenate a prefix and a variable name.
*/
static char_u *cat_prefix_varname(int prefix, char_u *name)
char_u *cat_prefix_varname(int prefix, const char_u *name)
FUNC_ATTR_NONNULL_ALL
{
size_t len = STRLEN(name) + 3;

View File

@ -117,8 +117,12 @@ char_u *get_function_name(expand_T *xp, int idx)
intidx = -1;
if (intidx < 0) {
name = get_user_func_name(xp, idx);
if (name != NULL)
if (name != NULL) {
if (*name != '<' && STRNCMP("g:", xp->xp_pattern, 2) == 0) {
return cat_prefix_varname('g', name);
}
return name;
}
}
while ((size_t)++intidx < ARRAY_SIZE(functions)
&& functions[intidx].name[0] == '\0') {

View File

@ -5117,6 +5117,18 @@ ExpandFromContext (
if (xp->xp_context == EXPAND_PACKADD) {
return ExpandPackAddDir(pat, num_file, file);
}
// When expanding a function name starting with s:, match the <SNR>nr_
// prefix.
char_u *tofree = NULL;
if (xp->xp_context == EXPAND_USER_FUNC && STRNCMP(pat, "^s:", 3) == 0) {
const size_t len = STRLEN(pat) + 20;
tofree = xmalloc(len);
snprintf((char *)tofree, len, "^<SNR>\\d\\+_%s", pat + 3);
pat = tofree;
}
if (xp->xp_context == EXPAND_LUA) {
ILOG("PAT %s", pat);
return nlua_expand_pat(xp, pat, num_file, file);
@ -5195,6 +5207,7 @@ ExpandFromContext (
}
vim_regfree(regmatch.regprog);
xfree(tofree);
return ret;
}

View File

@ -569,6 +569,21 @@ func Test_cmdline_complete_user_cmd()
delcommand Foo
endfunc
func s:ScriptLocalFunction()
echo 'yes'
endfunc
func Test_cmdline_complete_user_func()
call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
call assert_match('"func Test_cmdline_complete_user', @:)
call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
" g: prefix also works
call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
endfunc
func Test_cmdline_complete_user_names()
if has('unix') && executable('whoami')
let whoami = systemlist('whoami')[0]