Merge pull request #24768 from neovim/backport-24767-to-release-0.9

[Backport release-0.9] vim-patch:9.0.1734: :runtime completion fails for multiple args
This commit is contained in:
zeertzjq
2023-08-18 06:31:29 +08:00
committed by GitHub
3 changed files with 44 additions and 4 deletions

View File

@@ -1370,7 +1370,7 @@ char *skiptowhite(const char *p)
/// @param p /// @param p
/// ///
/// @return Pointer to the next whitespace character. /// @return Pointer to the next whitespace character.
char *skiptowhite_esc(char *p) char *skiptowhite_esc(const char *p)
FUNC_ATTR_PURE FUNC_ATTR_PURE
{ {
while (*p != ' ' && *p != '\t' && *p != NUL) { while (*p != ' ' && *p != '\t' && *p != NUL) {
@@ -1379,7 +1379,7 @@ char *skiptowhite_esc(char *p)
} }
p++; p++;
} }
return p; return (char *)p;
} }
/// Skip over text until '\n' or NUL. /// Skip over text until '\n' or NUL.

View File

@@ -262,6 +262,15 @@ void set_context_in_runtime_cmd(expand_T *xp, const char *arg)
char *p = skiptowhite(arg); char *p = skiptowhite(arg);
runtime_expand_flags runtime_expand_flags
= *p != NUL ? get_runtime_cmd_flags((char **)&arg, (size_t)(p - arg)) : 0; = *p != NUL ? get_runtime_cmd_flags((char **)&arg, (size_t)(p - arg)) : 0;
// Skip to the last argument.
while (*(p = skiptowhite_esc(arg)) != NUL) {
if (runtime_expand_flags == 0) {
// When there are multiple arguments and [where] is not specified,
// use an unrelated non-zero flag to avoid expanding [where].
runtime_expand_flags = DIP_ALL;
}
arg = skipwhite(p);
}
xp->xp_context = EXPAND_RUNTIME; xp->xp_context = EXPAND_RUNTIME;
xp->xp_pattern = (char *)arg; xp->xp_pattern = (char *)arg;
} }

View File

@@ -388,9 +388,9 @@ func Test_runtime_completion()
call writefile([], optdir . '/../Aunrelated') call writefile([], optdir . '/../Aunrelated')
exe 'set rtp=' . &packpath . '/runtime' exe 'set rtp=' . &packpath . '/runtime'
func Check_runtime_completion(arg, arg1, res) func Check_runtime_completion(arg, arg_prev, res)
call feedkeys(':runtime ' .. a:arg .. "\<C-A>\<C-B>\"\<CR>", 'xt') call feedkeys(':runtime ' .. a:arg .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"runtime ' .. a:arg1 .. join(a:res), @:) call assert_equal('"runtime ' .. a:arg_prev .. join(a:res), @:)
call assert_equal(a:res, getcompletion(a:arg, 'runtime')) call assert_equal(a:res, getcompletion(a:arg, 'runtime'))
endfunc endfunc
@@ -404,39 +404,70 @@ func Test_runtime_completion()
\ ['PACK']) \ ['PACK'])
call Check_runtime_completion('A', '', call Check_runtime_completion('A', '',
\ ['Aextra/', 'Arunfoo.vim', 'ALL']) \ ['Aextra/', 'Arunfoo.vim', 'ALL'])
call Check_runtime_completion('Other.vim ', 'Other.vim ',
\ ['Aextra/', 'Arunfoo.vim'])
call Check_runtime_completion('Aextra/', '', call Check_runtime_completion('Aextra/', '',
\ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/']) \ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
call Check_runtime_completion('Other.vim Aextra/', 'Other.vim ',
\ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
call Check_runtime_completion('START ', 'START ', call Check_runtime_completion('START ', 'START ',
\ ['Aextra/', 'Astartfoo.vim']) \ ['Aextra/', 'Astartfoo.vim'])
call Check_runtime_completion('START Other.vim ', 'START Other.vim ',
\ ['Aextra/', 'Astartfoo.vim'])
call Check_runtime_completion('START A', 'START ', call Check_runtime_completion('START A', 'START ',
\ ['Aextra/', 'Astartfoo.vim']) \ ['Aextra/', 'Astartfoo.vim'])
call Check_runtime_completion('START Other.vim A', 'START Other.vim ',
\ ['Aextra/', 'Astartfoo.vim'])
call Check_runtime_completion('START Aextra/', 'START ', call Check_runtime_completion('START Aextra/', 'START ',
\ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/']) \ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
call Check_runtime_completion('START Other.vim Aextra/', 'START Other.vim ',
\ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
call Check_runtime_completion('OPT ', 'OPT ', call Check_runtime_completion('OPT ', 'OPT ',
\ ['Aextra/', 'Aoptfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim'])
call Check_runtime_completion('OPT Other.vim ', 'OPT Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim'])
call Check_runtime_completion('OPT A', 'OPT ', call Check_runtime_completion('OPT A', 'OPT ',
\ ['Aextra/', 'Aoptfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim'])
call Check_runtime_completion('OPT Other.vim A', 'OPT Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim'])
call Check_runtime_completion('OPT Aextra/', 'OPT ', call Check_runtime_completion('OPT Aextra/', 'OPT ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/']) \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
call Check_runtime_completion('OPT Other.vim Aextra/', 'OPT Other.vim ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
call Check_runtime_completion('PACK ', 'PACK ', call Check_runtime_completion('PACK ', 'PACK ',
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('PACK Other.vim ', 'PACK Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('PACK A', 'PACK ', call Check_runtime_completion('PACK A', 'PACK ',
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('PACK Other.vim A', 'PACK Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('PACK Aextra/', 'PACK ', call Check_runtime_completion('PACK Aextra/', 'PACK ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/', \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/']) \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
call Check_runtime_completion('PACK Other.vim Aextra/', 'PACK Other.vim ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
call Check_runtime_completion('ALL ', 'ALL ', call Check_runtime_completion('ALL ', 'ALL ',
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('ALL Other.vim ', 'ALL Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('ALL A', 'ALL ', call Check_runtime_completion('ALL A', 'ALL ',
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim']) \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('ALL Other.vim A', 'ALL Other.vim ',
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
call Check_runtime_completion('ALL Aextra/', 'ALL ', call Check_runtime_completion('ALL Aextra/', 'ALL ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/', \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
\ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/', \ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/']) \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
call Check_runtime_completion('ALL Other.vim Aextra/', 'ALL Other.vim ',
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
\ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
delfunc Check_runtime_completion delfunc Check_runtime_completion
endfunc endfunc