mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:9.0.1714: getcompletion() "cmdline" fails after :autocmd
Problem: getcompletion() "cmdline" fails after :autocmd
Solution: Use set_cmd_context() instead of set_one_cmd_context().
closes: vim/vim#12804
e4c79d3615
This commit is contained in:
@@ -3479,7 +3479,6 @@ void wildmenu_cleanup(CmdlineInfo *cclp)
|
|||||||
/// "getcompletion()" function
|
/// "getcompletion()" function
|
||||||
void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||||
{
|
{
|
||||||
char *pat;
|
|
||||||
expand_T xpc;
|
expand_T xpc;
|
||||||
bool filtered = false;
|
bool filtered = false;
|
||||||
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
|
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
|
||||||
@@ -3510,9 +3509,10 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
const char *pattern = tv_get_string(&argvars[0]);
|
const char *pattern = tv_get_string(&argvars[0]);
|
||||||
|
|
||||||
if (strcmp(type, "cmdline") == 0) {
|
if (strcmp(type, "cmdline") == 0) {
|
||||||
set_one_cmd_context(&xpc, pattern);
|
const int cmdline_len = (int)strlen(pattern);
|
||||||
|
set_cmd_context(&xpc, (char *)pattern, cmdline_len, cmdline_len, false);
|
||||||
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
||||||
xpc.xp_col = (int)strlen(pattern);
|
xpc.xp_col = cmdline_len;
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3539,6 +3539,8 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
|
;
|
||||||
|
char *pat;
|
||||||
if (cmdline_fuzzy_completion_supported(&xpc)) {
|
if (cmdline_fuzzy_completion_supported(&xpc)) {
|
||||||
// when fuzzy matching, don't modify the search string
|
// when fuzzy matching, don't modify the search string
|
||||||
pat = xstrdup(xpc.xp_pattern);
|
pat = xstrdup(xpc.xp_pattern);
|
||||||
|
@@ -296,9 +296,6 @@ const char *set_context_in_user_cmdarg(const char *cmd FUNC_ATTR_UNUSED, const c
|
|||||||
return set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit);
|
return set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit);
|
||||||
}
|
}
|
||||||
if (context == EXPAND_COMMANDS) {
|
if (context == EXPAND_COMMANDS) {
|
||||||
if (xp->xp_context == EXPAND_NOTHING) {
|
|
||||||
xp->xp_context = context;
|
|
||||||
}
|
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
if (context == EXPAND_MAPPINGS) {
|
if (context == EXPAND_MAPPINGS) {
|
||||||
|
@@ -601,6 +601,8 @@ func Test_getcompletion()
|
|||||||
call assert_true(index(l, 'taglist(') >= 0)
|
call assert_true(index(l, 'taglist(') >= 0)
|
||||||
let l = getcompletion('call paint', 'cmdline')
|
let l = getcompletion('call paint', 'cmdline')
|
||||||
call assert_equal([], l)
|
call assert_equal([], l)
|
||||||
|
let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
|
||||||
|
call assert_equal(['<buffer>'], l)
|
||||||
|
|
||||||
func T(a, c, p)
|
func T(a, c, p)
|
||||||
let g:cmdline_compl_params = [a:a, a:c, a:p]
|
let g:cmdline_compl_params = [a:a, a:c, a:p]
|
||||||
@@ -3636,14 +3638,15 @@ func Test_rulerformat_position()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_usercmd_completion()
|
func Test_getcompletion_usercmd()
|
||||||
let g:complete=[]
|
|
||||||
command! -nargs=* -complete=command TestCompletion echo <q-args>
|
command! -nargs=* -complete=command TestCompletion echo <q-args>
|
||||||
let g:complete = getcompletion('TestCompletion ', 'cmdline')
|
|
||||||
let a = getcompletion('', 'cmdline')
|
|
||||||
|
|
||||||
call assert_equal(a, g:complete)
|
call assert_equal(getcompletion('', 'cmdline'),
|
||||||
|
\ getcompletion('TestCompletion ', 'cmdline'))
|
||||||
|
call assert_equal(['<buffer>'],
|
||||||
|
\ getcompletion('TestCompletion map <bu', 'cmdline'))
|
||||||
|
|
||||||
delcom TestCompletion
|
delcom TestCompletion
|
||||||
unlet! g:complete
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user