mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1227: no cmdline completion for :runtime
Problem: No cmdline completion for :runtime.
Solution: Add completion for :runtime. (closes vim/vim#11853, closes vim/vim#11447)
Improve the resulting matches.
a6759381a5
This commit is contained in:
parent
5ac34cf55d
commit
6644786db0
@ -109,6 +109,7 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp)
|
||||
&& xp->xp_context != EXPAND_OLD_SETTING
|
||||
&& xp->xp_context != EXPAND_OWNSYNTAX
|
||||
&& xp->xp_context != EXPAND_PACKADD
|
||||
&& xp->xp_context != EXPAND_RUNTIME
|
||||
&& xp->xp_context != EXPAND_SHELLCMD
|
||||
&& xp->xp_context != EXPAND_TAGS
|
||||
&& xp->xp_context != EXPAND_TAGS_LISTFILES
|
||||
@ -1211,6 +1212,7 @@ char *addstar(char *fname, size_t len, int context)
|
||||
if (context == EXPAND_HELP
|
||||
|| context == EXPAND_CHECKHEALTH
|
||||
|| context == EXPAND_COLORS
|
||||
|| context == EXPAND_RUNTIME
|
||||
|| context == EXPAND_COMPILER
|
||||
|| context == EXPAND_OWNSYNTAX
|
||||
|| context == EXPAND_FILETYPE
|
||||
@ -2072,6 +2074,11 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa
|
||||
xp->xp_pattern = (char *)arg;
|
||||
break;
|
||||
|
||||
case CMD_runtime:
|
||||
xp->xp_context = EXPAND_RUNTIME;
|
||||
xp->xp_pattern = (char *)arg;
|
||||
break;
|
||||
|
||||
case CMD_compiler:
|
||||
xp->xp_context = EXPAND_COMPILER;
|
||||
xp->xp_pattern = (char *)arg;
|
||||
@ -2712,6 +2719,11 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
char *directories[] = { "colors", NULL };
|
||||
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches, directories);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_RUNTIME) {
|
||||
char *directories[] = { "", NULL };
|
||||
return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_PRNEXT, numMatches,
|
||||
matches, directories);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_COMPILER) {
|
||||
char *directories[] = { "compiler", NULL };
|
||||
return ExpandRTDir(pat, 0, numMatches, matches, directories);
|
||||
|
@ -1194,11 +1194,22 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
|
||||
// TODO(bfredl): this is bullshit, expandpath should not reinvent path logic.
|
||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
||||
size_t size = strlen(dirnames[i]) + pat_len + 16;
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
|
||||
globpath(p_rtp, s, &ga, 0);
|
||||
xfree(s);
|
||||
size_t size = strlen(dirnames[i]) + pat_len * 2 + 26;
|
||||
char *buf = xmalloc(size);
|
||||
if (*dirnames[i] == NUL) {
|
||||
// empty dir used for :runtime
|
||||
if (path_tail(pat) == pat) {
|
||||
// no path separator, match dir names and script files
|
||||
snprintf(buf, size, "\\(%s*.\\(vim\\|lua\\)\\)\\|\\(%s*\\)", pat, pat);
|
||||
} else {
|
||||
// has path separator, match script files
|
||||
snprintf(buf, size, "%s*.vim", pat);
|
||||
}
|
||||
} else {
|
||||
snprintf(buf, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
|
||||
}
|
||||
globpath(p_rtp, buf, &ga, 0);
|
||||
xfree(buf);
|
||||
}
|
||||
|
||||
if (flags & DIP_START) {
|
||||
@ -1241,18 +1252,53 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *match = ((char **)ga.ga_data)[i];
|
||||
char *s = match;
|
||||
char *e = s + strlen(s);
|
||||
char *res_start = s;
|
||||
if ((flags & DIP_PRNEXT) != 0) {
|
||||
char *p = strstr(match, pat);
|
||||
if (p != NULL) {
|
||||
// Drop what comes before "pat" in the match, so that for
|
||||
// match "/long/path/syntax/cpp.vim" with pattern
|
||||
// "syntax/cp" we only keep "syntax/cpp.vim".
|
||||
res_start = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
|
||||
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
|
||||
e -= 4;
|
||||
for (s = e; s > match; MB_PTR_BACK(match, s)) {
|
||||
if (vim_ispathsep(*s)) {
|
||||
break;
|
||||
if (res_start == s) {
|
||||
// Only keep the file name.
|
||||
// Remove file ext only if flag DIP_PRNEXT is not present.
|
||||
if ((flags & DIP_PRNEXT) == 0) {
|
||||
e -= 4;
|
||||
}
|
||||
for (s = e; s > match; MB_PTR_BACK(match, s)) {
|
||||
if (s < match) {
|
||||
break;
|
||||
}
|
||||
if (vim_ispathsep(*s)) {
|
||||
res_start = s + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
s++;
|
||||
|
||||
*e = NUL;
|
||||
assert((e - s) + 1 >= 0);
|
||||
memmove(match, s, (size_t)(e - s) + 1);
|
||||
}
|
||||
|
||||
if (res_start > match) {
|
||||
assert((e - res_start) + 1 >= 0);
|
||||
memmove(match, res_start, (size_t)(e - res_start) + 1);
|
||||
}
|
||||
|
||||
// remove entries that look like backup files
|
||||
if (e > s && e[-1] == '~') {
|
||||
xfree(match);
|
||||
char **fnames = (char **)ga.ga_data;
|
||||
for (int j = i + 1; j < ga.ga_len; ++j) {
|
||||
fnames[j - 1] = fnames[j];
|
||||
}
|
||||
ga.ga_len--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,7 @@ 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_PRNEXT 0x100 // for print also file extension
|
||||
#define DIP_DIRFILE 0x200 // find both files and directories
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
@ -542,6 +542,15 @@ func Test_getcompletion()
|
||||
call assert_true(index(l, '<buffer>') >= 0)
|
||||
let l = getcompletion('not', 'mapclear')
|
||||
call assert_equal([], l)
|
||||
|
||||
let l = getcompletion('', 'runtime')
|
||||
call assert_true(index(l, 'defaults.vim') >= 0)
|
||||
let l = getcompletion('synt', 'runtime')
|
||||
call assert_true(index(l, 'syntax') >= 0)
|
||||
let l = getcompletion('syntax/vi', 'runtime')
|
||||
call assert_true(index(l, 'syntax/vim.vim') >= 0)
|
||||
let l = getcompletion('notexitsts', 'runtime')
|
||||
call assert_equal([], l)
|
||||
|
||||
let l = getcompletion('.', 'shellcmd')
|
||||
call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
|
||||
|
@ -89,6 +89,7 @@ static const char *command_complete[] = {
|
||||
[EXPAND_SYNTIME] = "syntime",
|
||||
[EXPAND_SETTINGS] = "option",
|
||||
[EXPAND_PACKADD] = "packadd",
|
||||
[EXPAND_RUNTIME] = "runtime",
|
||||
[EXPAND_SHELLCMD] = "shellcmd",
|
||||
[EXPAND_SIGN] = "sign",
|
||||
[EXPAND_TAGS] = "tag",
|
||||
|
@ -156,6 +156,7 @@ enum {
|
||||
EXPAND_DIFF_BUFFERS,
|
||||
EXPAND_BREAKPOINT,
|
||||
EXPAND_SCRIPTNAMES,
|
||||
EXPAND_RUNTIME,
|
||||
EXPAND_CHECKHEALTH,
|
||||
EXPAND_LUA,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user