Merge pull request #29398 from neovim/backport-29397-to-release-0.10

vim-patch:9.1.0498: getcmdcompltype() interferes with cmdline completion
This commit is contained in:
zeertzjq 2024-06-19 06:00:15 +08:00 committed by GitHub
commit b16fe558ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 7 deletions

View File

@ -4070,18 +4070,22 @@ static char *get_cmdline_completion(void)
return NULL;
}
set_expand_context(p->xpc);
if (p->xpc->xp_context == EXPAND_UNSUCCESSFUL) {
int xp_context = p->xpc->xp_context;
if (xp_context == EXPAND_NOTHING) {
set_expand_context(p->xpc);
xp_context = p->xpc->xp_context;
p->xpc->xp_context = EXPAND_NOTHING;
}
if (xp_context == EXPAND_UNSUCCESSFUL) {
return NULL;
}
char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context);
char *cmd_compl = get_user_cmd_complete(NULL, xp_context);
if (cmd_compl == NULL) {
return NULL;
}
if (p->xpc->xp_context == EXPAND_USER_LIST
|| p->xpc->xp_context == EXPAND_USER_DEFINED) {
if (xp_context == EXPAND_USER_LIST || xp_context == EXPAND_USER_DEFINED) {
size_t buflen = strlen(cmd_compl) + strlen(p->xpc->xp_arg) + 2;
char *buffer = xmalloc(buflen);
snprintf(buffer, buflen, "%s,%s", cmd_compl, p->xpc->xp_arg);

View File

@ -3736,7 +3736,7 @@ func Test_cmdline_complete_bang_cmd_argument()
endfunc
func Call_cmd_funcs()
return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
return [getcmdpos(), getcmdscreenpos(), getcmdcompltype()]
endfunc
func Test_screenpos_and_completion()
@ -3744,13 +3744,24 @@ func Test_screenpos_and_completion()
call assert_equal(0, getcmdscreenpos())
call assert_equal('', getcmdcompltype())
cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
cnoremap <expr> <F2> string(Call_cmd_funcs())
call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
call assert_equal("\"let a[6, 7, 'var']", @:)
call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
call assert_equal("\"quit [6, 7, '']", @:)
call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
call assert_equal("\"nosuchcommand [15, 16, '']", @:)
" Check that getcmdcompltype() doesn't interfere with cmdline completion.
let g:results = []
cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
call assert_equal([
\ ['sign undefine', 14, 15, 'sign'],
\ ['sign unplace', 13, 14, 'sign'],
\ ['sign un', 8, 9, 'sign']], g:results)
unlet g:results
cunmap <F2>
endfunc