mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
b650d2d8d9
commit
a4ea602788
@ -3007,7 +3007,8 @@ static size_t varnamebuflen = 0;
|
|||||||
/*
|
/*
|
||||||
* Function to concatenate a prefix and a variable name.
|
* 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;
|
size_t len = STRLEN(name) + 3;
|
||||||
|
|
||||||
|
@ -117,8 +117,12 @@ char_u *get_function_name(expand_T *xp, int idx)
|
|||||||
intidx = -1;
|
intidx = -1;
|
||||||
if (intidx < 0) {
|
if (intidx < 0) {
|
||||||
name = get_user_func_name(xp, idx);
|
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;
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while ((size_t)++intidx < ARRAY_SIZE(functions)
|
while ((size_t)++intidx < ARRAY_SIZE(functions)
|
||||||
&& functions[intidx].name[0] == '\0') {
|
&& functions[intidx].name[0] == '\0') {
|
||||||
|
@ -5117,6 +5117,18 @@ ExpandFromContext (
|
|||||||
if (xp->xp_context == EXPAND_PACKADD) {
|
if (xp->xp_context == EXPAND_PACKADD) {
|
||||||
return ExpandPackAddDir(pat, num_file, file);
|
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) {
|
if (xp->xp_context == EXPAND_LUA) {
|
||||||
ILOG("PAT %s", pat);
|
ILOG("PAT %s", pat);
|
||||||
return nlua_expand_pat(xp, pat, num_file, file);
|
return nlua_expand_pat(xp, pat, num_file, file);
|
||||||
@ -5195,6 +5207,7 @@ ExpandFromContext (
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim_regfree(regmatch.regprog);
|
vim_regfree(regmatch.regprog);
|
||||||
|
xfree(tofree);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -569,6 +569,21 @@ func Test_cmdline_complete_user_cmd()
|
|||||||
delcommand Foo
|
delcommand Foo
|
||||||
endfunc
|
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()
|
func Test_cmdline_complete_user_names()
|
||||||
if has('unix') && executable('whoami')
|
if has('unix') && executable('whoami')
|
||||||
let whoami = systemlist('whoami')[0]
|
let whoami = systemlist('whoami')[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user