fix(completion): include lua syntaxes in :ownsyntax completion (#21941)

This just removes DIP_LUA and always executes its branches.
Also add tests for cmdline completion for other lua runtime files.
This commit is contained in:
zeertzjq
2023-01-22 11:19:58 +08:00
committed by GitHub
parent 108452aaba
commit 18fb669b9b
4 changed files with 56 additions and 51 deletions

View File

@@ -2710,11 +2710,11 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
}
if (xp->xp_context == EXPAND_COLORS) {
char *directories[] = { "colors", NULL };
return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, numMatches, matches, directories);
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches, directories);
}
if (xp->xp_context == EXPAND_COMPILER) {
char *directories[] = { "compiler", NULL };
return ExpandRTDir(pat, DIP_LUA, numMatches, matches, directories);
return ExpandRTDir(pat, 0, numMatches, matches, directories);
}
if (xp->xp_context == EXPAND_OWNSYNTAX) {
char *directories[] = { "syntax", NULL };
@@ -2722,7 +2722,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
}
if (xp->xp_context == EXPAND_FILETYPE) {
char *directories[] = { "syntax", "indent", "ftplugin", NULL };
return ExpandRTDir(pat, DIP_LUA, numMatches, matches, directories);
return ExpandRTDir(pat, 0, numMatches, matches, directories);
}
if (xp->xp_context == EXPAND_USER_LIST) {
return ExpandUserList(xp, matches, numMatches);

View File

@@ -1175,12 +1175,11 @@ void ex_packadd(exarg_T *eap)
/// Expand color scheme, compiler or filetype names.
/// Search from 'runtimepath':
/// 'runtimepath'/{dirnames}/{pat}.vim
/// When "flags" has DIP_START: search also from 'start' of 'packpath':
/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
/// When "flags" has DIP_LUA: search also performed for .lua files
/// 'runtimepath'/{dirnames}/{pat}.(vim|lua)
/// When "flags" has DIP_START: search also from "start" of 'packpath':
/// 'packpath'/pack/*/start/*/{dirnames}/{pat}.(vim|lua)
/// When "flags" has DIP_OPT: search also from "opt" of 'packpath':
/// 'packpath'/pack/*/opt/*/{dirnames}/{pat}.(vim|lua)
/// "dirnames" is an array with one or more directory names.
int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirnames[])
{
@@ -1197,10 +1196,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = xmalloc(size);
snprintf(s, size, "%s/%s*.vim", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0);
if (flags & DIP_LUA) {
snprintf(s, size, "%s/%s*.lua", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0);
}
snprintf(s, size, "%s/%s*.lua", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0);
xfree(s);
}
@@ -1210,10 +1207,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = xmalloc(size);
snprintf(s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
if (flags & DIP_LUA) {
snprintf(s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
}
snprintf(s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
xfree(s);
}
@@ -1222,10 +1217,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = xmalloc(size);
snprintf(s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
if (flags & DIP_LUA) {
snprintf(s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
}
snprintf(s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
xfree(s);
}
}
@@ -1236,10 +1229,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = xmalloc(size);
snprintf(s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
if (flags & DIP_LUA) {
snprintf(s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
}
snprintf(s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
xfree(s);
}
@@ -1248,10 +1239,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = xmalloc(size);
snprintf(s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
if (flags & DIP_LUA) {
snprintf(s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
}
snprintf(s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
xfree(s);
}
}
@@ -1261,8 +1250,7 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *s = match;
char *e = s + strlen(s);
if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
|| ((flags & DIP_LUA)
&& STRNICMP(e - 4, ".lua", 4) == 0))) {
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
e -= 4;
for (s = e; s > match; MB_PTR_BACK(match, s)) {
if (vim_ispathsep(*s)) {

View File

@@ -105,7 +105,6 @@ typedef kvec_t(char *) CharVec;
#define DIP_NORTP 0x20 // do not use 'runtimepath'
#define DIP_NOAFTER 0x40 // skip "after" directories
#define DIP_AFTER 0x80 // only use "after" directories
#define DIP_LUA 0x100 // also use ".lua" files
#define DIP_DIRFILE 0x200 // find both files and directories
#ifdef INCLUDE_GENERATED_DECLARATIONS