mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(completion): don't add backslashes to runtime pattern (#24296)
Problem: Bashslashes added as regexp in runtime completion may be treated as path separator with some 'isfname' value. Solution: Make curly braces work for runtime completion and use it.
This commit is contained in:
parent
b9a0e762f1
commit
fbeef0d4ef
@ -1163,7 +1163,7 @@ static bool has_env_var(char *p)
|
|||||||
|
|
||||||
// Return true if "p" contains a special wildcard character, one that Vim
|
// Return true if "p" contains a special wildcard character, one that Vim
|
||||||
// cannot expand, requires using a shell.
|
// cannot expand, requires using a shell.
|
||||||
static bool has_special_wildchar(char *p)
|
static bool has_special_wildchar(char *p, int flags)
|
||||||
{
|
{
|
||||||
for (; *p; MB_PTR_ADV(p)) {
|
for (; *p; MB_PTR_ADV(p)) {
|
||||||
// Disallow line break characters.
|
// Disallow line break characters.
|
||||||
@ -1174,6 +1174,10 @@ static bool has_special_wildchar(char *p)
|
|||||||
if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n') {
|
if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n') {
|
||||||
p++;
|
p++;
|
||||||
} else if (vim_strchr(SPECIAL_WILDCHAR, (uint8_t)(*p)) != NULL) {
|
} else if (vim_strchr(SPECIAL_WILDCHAR, (uint8_t)(*p)) != NULL) {
|
||||||
|
// Need a shell for curly braces only when including non-existing files.
|
||||||
|
if (*p == '{' && !(flags & EW_NOTFOUND)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// A { must be followed by a matching }.
|
// A { must be followed by a matching }.
|
||||||
if (*p == '{' && vim_strchr(p, '}') == NULL) {
|
if (*p == '{' && vim_strchr(p, '}') == NULL) {
|
||||||
continue;
|
continue;
|
||||||
@ -1233,7 +1237,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i
|
|||||||
// avoids starting the shell for each argument separately.
|
// avoids starting the shell for each argument separately.
|
||||||
// For `=expr` do use the internal function.
|
// For `=expr` do use the internal function.
|
||||||
for (int i = 0; i < num_pat; i++) {
|
for (int i = 0; i < num_pat; i++) {
|
||||||
if (has_special_wildchar(pat[i])
|
if (has_special_wildchar(pat[i], flags)
|
||||||
&& !(vim_backtick(pat[i]) && pat[i][1] == '=')) {
|
&& !(vim_backtick(pat[i]) && pat[i][1] == '=')) {
|
||||||
return os_expand_wildcards(num_pat, pat, num_file, file, flags);
|
return os_expand_wildcards(num_pat, pat, num_file, file, flags);
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, vo
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ew_flags = ((flags & DIP_DIR) ? EW_DIR : EW_FILE)
|
int ew_flags = ((flags & DIP_DIR) ? EW_DIR : EW_FILE)
|
||||||
| (flags & DIP_DIRFILE) ? (EW_DIR|EW_FILE) : 0;
|
| ((flags & DIP_DIRFILE) ? (EW_DIR|EW_FILE) : 0);
|
||||||
|
|
||||||
// Expand wildcards, invoke the callback for each match.
|
// Expand wildcards, invoke the callback for each match.
|
||||||
if (gen_expand_wildcards(1, &buf, &num_files, &files, ew_flags) == OK) {
|
if (gen_expand_wildcards(1, &buf, &num_files, &files, ew_flags) == OK) {
|
||||||
@ -1222,9 +1222,9 @@ static void ExpandRTDir_int(char *pat, size_t pat_len, int flags, bool keep_ext,
|
|||||||
bool expand_dirs = false;
|
bool expand_dirs = false;
|
||||||
|
|
||||||
if (*dirnames[i] == NUL) { // empty dir used for :runtime
|
if (*dirnames[i] == NUL) { // empty dir used for :runtime
|
||||||
snprintf(tail, tail_buflen, "%s*.\\(vim\\|lua\\)", pat);
|
snprintf(tail, tail_buflen, "%s*.{vim,lua}", pat);
|
||||||
} else {
|
} else {
|
||||||
snprintf(tail, tail_buflen, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
|
snprintf(tail, tail_buflen, "%s/%s*.{vim,lua}", dirnames[i], pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
expand:
|
expand:
|
||||||
|
@ -18,7 +18,10 @@ describe('runtime:', function()
|
|||||||
io.open(init, 'w'):close() -- touch init file
|
io.open(init, 'w'):close() -- touch init file
|
||||||
clear{args = {'-u', init}}
|
clear{args = {'-u', init}}
|
||||||
exec('set rtp+=' .. plug_dir)
|
exec('set rtp+=' .. plug_dir)
|
||||||
exec('set completeslash=slash')
|
exec([[
|
||||||
|
set completeslash=slash
|
||||||
|
set isfname+=(,)
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
teardown(function()
|
teardown(function()
|
||||||
|
Loading…
Reference in New Issue
Block a user