aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-26 09:44:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-01-26 11:55:32 +0800
commit6644786db078e019426f90cf85da50e3fa1b6a67 (patch)
treead044561cd9b9c336ade9661f54e18fcbd9f7e46
parent5ac34cf55db2b00c044fa95f75766dd89dd36ba9 (diff)
downloadrneovim-6644786db078e019426f90cf85da50e3fa1b6a67.tar.gz
rneovim-6644786db078e019426f90cf85da50e3fa1b6a67.tar.bz2
rneovim-6644786db078e019426f90cf85da50e3fa1b6a67.zip
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. https://github.com/vim/vim/commit/a6759381a590b2d395e05b109ca9ccfc356be5a8
-rw-r--r--src/nvim/cmdexpand.c12
-rw-r--r--src/nvim/runtime.c70
-rw-r--r--src/nvim/runtime.h1
-rw-r--r--src/nvim/testdir/test_cmdline.vim9
-rw-r--r--src/nvim/usercmd.c1
-rw-r--r--src/nvim/vim.h1
6 files changed, 82 insertions, 12 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index be815151ef..3e06814d6a 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -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);
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 24500b80b9..068a43c790 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -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--;
}
}
diff --git a/src/nvim/runtime.h b/src/nvim/runtime.h
index 97063b900c..be2663d52a 100644
--- a/src/nvim/runtime.h
+++ b/src/nvim/runtime.h
@@ -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
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index cf1d56ae38..8f79f0d8a0 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -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 =~ "\\./"'))
diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c
index 31cb1e8936..ef13f67e49 100644
--- a/src/nvim/usercmd.c
+++ b/src/nvim/usercmd.c
@@ -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",
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index c4baa911f1..3c765f8eb2 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -156,6 +156,7 @@ enum {
EXPAND_DIFF_BUFFERS,
EXPAND_BREAKPOINT,
EXPAND_SCRIPTNAMES,
+ EXPAND_RUNTIME,
EXPAND_CHECKHEALTH,
EXPAND_LUA,
};