mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
Merge pull request #22002 from zeertzjq/vim-9.0.1227
vim-patch:9.0.{1227,1231,1238,1242}: cmdline completion for :runtime
This commit is contained in:
commit
a0a1125159
@ -2991,6 +2991,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
|
|||||||
messages |:messages| suboptions
|
messages |:messages| suboptions
|
||||||
option options
|
option options
|
||||||
packadd optional package |pack-add| names
|
packadd optional package |pack-add| names
|
||||||
|
runtime |:runtime| completion
|
||||||
scriptnames sourced script names |:scriptnames|
|
scriptnames sourced script names |:scriptnames|
|
||||||
shellcmd Shell command
|
shellcmd Shell command
|
||||||
sign |:sign| suboptions
|
sign |:sign| suboptions
|
||||||
|
@ -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_OLD_SETTING
|
||||||
&& xp->xp_context != EXPAND_OWNSYNTAX
|
&& xp->xp_context != EXPAND_OWNSYNTAX
|
||||||
&& xp->xp_context != EXPAND_PACKADD
|
&& xp->xp_context != EXPAND_PACKADD
|
||||||
|
&& xp->xp_context != EXPAND_RUNTIME
|
||||||
&& xp->xp_context != EXPAND_SHELLCMD
|
&& xp->xp_context != EXPAND_SHELLCMD
|
||||||
&& xp->xp_context != EXPAND_TAGS
|
&& xp->xp_context != EXPAND_TAGS
|
||||||
&& xp->xp_context != EXPAND_TAGS_LISTFILES
|
&& xp->xp_context != EXPAND_TAGS_LISTFILES
|
||||||
@ -1215,6 +1216,7 @@ char *addstar(char *fname, size_t len, int context)
|
|||||||
|| context == EXPAND_OWNSYNTAX
|
|| context == EXPAND_OWNSYNTAX
|
||||||
|| context == EXPAND_FILETYPE
|
|| context == EXPAND_FILETYPE
|
||||||
|| context == EXPAND_PACKADD
|
|| context == EXPAND_PACKADD
|
||||||
|
|| context == EXPAND_RUNTIME
|
||||||
|| ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS)
|
|| ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS)
|
||||||
&& fname[0] == '/')) {
|
&& fname[0] == '/')) {
|
||||||
retval = xstrnsave(fname, len);
|
retval = xstrnsave(fname, len);
|
||||||
@ -2092,6 +2094,10 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa
|
|||||||
xp->xp_pattern = (char *)arg;
|
xp->xp_pattern = (char *)arg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CMD_runtime:
|
||||||
|
set_context_in_runtime_cmd(xp, arg);
|
||||||
|
break;
|
||||||
|
|
||||||
#ifdef HAVE_WORKING_LIBINTL
|
#ifdef HAVE_WORKING_LIBINTL
|
||||||
case CMD_language:
|
case CMD_language:
|
||||||
return set_context_in_lang_cmd(xp, arg);
|
return set_context_in_lang_cmd(xp, arg);
|
||||||
@ -2733,6 +2739,9 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
|||||||
if (xp->xp_context == EXPAND_PACKADD) {
|
if (xp->xp_context == EXPAND_PACKADD) {
|
||||||
return ExpandPackAddDir(pat, numMatches, matches);
|
return ExpandPackAddDir(pat, numMatches, matches);
|
||||||
}
|
}
|
||||||
|
if (xp->xp_context == EXPAND_RUNTIME) {
|
||||||
|
return expand_runtime_cmd(pat, numMatches, matches);
|
||||||
|
}
|
||||||
|
|
||||||
// When expanding a function name starting with s:, match the <SNR>nr_
|
// When expanding a function name starting with s:, match the <SNR>nr_
|
||||||
// prefix.
|
// prefix.
|
||||||
@ -3201,11 +3210,12 @@ static int ExpandUserLua(expand_T *xp, int *num_file, char ***file)
|
|||||||
|
|
||||||
/// Expand `file` for all comma-separated directories in `path`.
|
/// Expand `file` for all comma-separated directories in `path`.
|
||||||
/// Adds matches to `ga`.
|
/// Adds matches to `ga`.
|
||||||
void globpath(char *path, char *file, garray_T *ga, int expand_options)
|
/// If "dirs" is true only expand directory names.
|
||||||
|
void globpath(char *path, char *file, garray_T *ga, int expand_options, bool dirs)
|
||||||
{
|
{
|
||||||
expand_T xpc;
|
expand_T xpc;
|
||||||
ExpandInit(&xpc);
|
ExpandInit(&xpc);
|
||||||
xpc.xp_context = EXPAND_FILES;
|
xpc.xp_context = dirs ? EXPAND_DIRECTORIES : EXPAND_FILES;
|
||||||
|
|
||||||
char *buf = xmalloc(MAXPATHL);
|
char *buf = xmalloc(MAXPATHL);
|
||||||
|
|
||||||
@ -3524,11 +3534,14 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false);
|
set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false);
|
||||||
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xpc.xp_context == EXPAND_SIGN) {
|
if (xpc.xp_context == EXPAND_SIGN) {
|
||||||
set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
|
set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
|
||||||
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
||||||
}
|
}
|
||||||
|
if (xpc.xp_context == EXPAND_RUNTIME) {
|
||||||
|
set_context_in_runtime_cmd(&xpc, xpc.xp_pattern);
|
||||||
|
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
|
||||||
|
}
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
if (cmdline_fuzzy_completion_supported(&xpc)) {
|
if (cmdline_fuzzy_completion_supported(&xpc)) {
|
||||||
|
@ -2983,7 +2983,7 @@ static void f_globpath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
if (file != NULL && !error) {
|
if (file != NULL && !error) {
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
ga_init(&ga, (int)sizeof(char *), 10);
|
ga_init(&ga, (int)sizeof(char *), 10);
|
||||||
globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags);
|
globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags, false);
|
||||||
|
|
||||||
if (rettv->v_type == VAR_STRING) {
|
if (rettv->v_type == VAR_STRING) {
|
||||||
rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n");
|
rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n");
|
||||||
|
@ -4824,12 +4824,12 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numM
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpandOldSetting(int *num_file, char ***file)
|
void ExpandOldSetting(int *numMatches, char ***matches)
|
||||||
{
|
{
|
||||||
char *var = NULL;
|
char *var = NULL;
|
||||||
|
|
||||||
*num_file = 0;
|
*numMatches = 0;
|
||||||
*file = xmalloc(sizeof(char_u *));
|
*matches = xmalloc(sizeof(char *));
|
||||||
|
|
||||||
// For a terminal key code expand_option_idx is < 0.
|
// For a terminal key code expand_option_idx is < 0.
|
||||||
if (expand_option_idx < 0) {
|
if (expand_option_idx < 0) {
|
||||||
@ -4862,8 +4862,8 @@ void ExpandOldSetting(int *num_file, char ***file)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*file[0] = buf;
|
*matches[0] = buf;
|
||||||
*num_file = 1;
|
*numMatches = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the value for the numeric or string option///opp in a nice format into
|
/// Get the value for the numeric or string option///opp in a nice format into
|
||||||
|
@ -1138,7 +1138,7 @@ static int expand_in_path(garray_T *const gap, char *const pattern, const int fl
|
|||||||
if (flags & EW_ADDSLASH) {
|
if (flags & EW_ADDSLASH) {
|
||||||
glob_flags |= WILD_ADD_SLASH;
|
glob_flags |= WILD_ADD_SLASH;
|
||||||
}
|
}
|
||||||
globpath(paths, pattern, gap, glob_flags);
|
globpath(paths, pattern, gap, glob_flags, false);
|
||||||
xfree(paths);
|
xfree(paths);
|
||||||
|
|
||||||
return gap->ga_len;
|
return gap->ga_len;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "nvim/ex_cmds_defs.h"
|
#include "nvim/ex_cmds_defs.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/ex_eval.h"
|
#include "nvim/ex_eval.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/gettext.h"
|
#include "nvim/gettext.h"
|
||||||
#include "nvim/globals.h"
|
#include "nvim/globals.h"
|
||||||
@ -208,31 +209,58 @@ void runtime_init(void)
|
|||||||
uv_mutex_init(&runtime_search_path_mutex);
|
uv_mutex_init(&runtime_search_path_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ":runtime [what] {name}"
|
/// Get DIP_ flags from the [where] argument of a :runtime command.
|
||||||
|
/// "*argp" is advanced to after the [where] argument.
|
||||||
|
static int get_runtime_cmd_flags(char **argp, size_t where_len)
|
||||||
|
{
|
||||||
|
char *arg = *argp;
|
||||||
|
|
||||||
|
if (where_len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(arg, "START", where_len) == 0) {
|
||||||
|
*argp = skipwhite(arg + where_len);
|
||||||
|
return DIP_START + DIP_NORTP;
|
||||||
|
}
|
||||||
|
if (strncmp(arg, "OPT", where_len) == 0) {
|
||||||
|
*argp = skipwhite(arg + where_len);
|
||||||
|
return DIP_OPT + DIP_NORTP;
|
||||||
|
}
|
||||||
|
if (strncmp(arg, "PACK", where_len) == 0) {
|
||||||
|
*argp = skipwhite(arg + where_len);
|
||||||
|
return DIP_START + DIP_OPT + DIP_NORTP;
|
||||||
|
}
|
||||||
|
if (strncmp(arg, "ALL", where_len) == 0) {
|
||||||
|
*argp = skipwhite(arg + where_len);
|
||||||
|
return DIP_START + DIP_OPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ":runtime [where] {name}"
|
||||||
void ex_runtime(exarg_T *eap)
|
void ex_runtime(exarg_T *eap)
|
||||||
{
|
{
|
||||||
char *arg = eap->arg;
|
char *arg = eap->arg;
|
||||||
char *p = skiptowhite(arg);
|
|
||||||
size_t len = (size_t)(p - arg);
|
|
||||||
int flags = eap->forceit ? DIP_ALL : 0;
|
int flags = eap->forceit ? DIP_ALL : 0;
|
||||||
|
char *p = skiptowhite(arg);
|
||||||
if (strncmp(arg, "START", len) == 0) {
|
flags += get_runtime_cmd_flags(&arg, (size_t)(p - arg));
|
||||||
flags += DIP_START + DIP_NORTP;
|
|
||||||
arg = skipwhite(arg + len);
|
|
||||||
} else if (strncmp(arg, "OPT", len) == 0) {
|
|
||||||
flags += DIP_OPT + DIP_NORTP;
|
|
||||||
arg = skipwhite(arg + len);
|
|
||||||
} else if (strncmp(arg, "PACK", len) == 0) {
|
|
||||||
flags += DIP_START + DIP_OPT + DIP_NORTP;
|
|
||||||
arg = skipwhite(arg + len);
|
|
||||||
} else if (strncmp(arg, "ALL", len) == 0) {
|
|
||||||
flags += DIP_START + DIP_OPT;
|
|
||||||
arg = skipwhite(arg + len);
|
|
||||||
}
|
|
||||||
|
|
||||||
source_runtime(arg, flags);
|
source_runtime(arg, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int runtime_expand_flags;
|
||||||
|
|
||||||
|
/// Set the completion context for the :runtime command.
|
||||||
|
void set_context_in_runtime_cmd(expand_T *xp, const char *arg)
|
||||||
|
{
|
||||||
|
char *p = skiptowhite(arg);
|
||||||
|
runtime_expand_flags
|
||||||
|
= *p != NUL ? get_runtime_cmd_flags((char **)&arg, (size_t)(p - arg)) : 0;
|
||||||
|
xp->xp_context = EXPAND_RUNTIME;
|
||||||
|
xp->xp_pattern = (char *)arg;
|
||||||
|
}
|
||||||
|
|
||||||
static void source_callback(char *fname, void *cookie)
|
static void source_callback(char *fname, void *cookie)
|
||||||
{
|
{
|
||||||
(void)do_source(fname, false, DOSO_NONE);
|
(void)do_source(fname, false, DOSO_NONE);
|
||||||
@ -1175,6 +1203,93 @@ void ex_packadd(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ExpandRTDir_int(char *pat, size_t pat_len, int flags, bool keep_ext, garray_T *gap,
|
||||||
|
char *dirnames[])
|
||||||
|
{
|
||||||
|
// TODO(bfredl): this is bullshit, expandpath should not reinvent path logic.
|
||||||
|
for (int i = 0; dirnames[i] != NULL; i++) {
|
||||||
|
const size_t buf_len = strlen(dirnames[i]) + pat_len + 31;
|
||||||
|
char *const buf = xmalloc(buf_len);
|
||||||
|
char *const tail = buf + 15;
|
||||||
|
const size_t tail_buflen = buf_len - 15;
|
||||||
|
int glob_flags = 0;
|
||||||
|
bool expand_dirs = false;
|
||||||
|
|
||||||
|
if (*dirnames[i] == NUL) { // empty dir used for :runtime
|
||||||
|
snprintf(tail, tail_buflen, "%s*.\\(vim\\|lua\\)", pat);
|
||||||
|
} else {
|
||||||
|
snprintf(tail, tail_buflen, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
|
||||||
|
}
|
||||||
|
|
||||||
|
expand:
|
||||||
|
if ((flags & DIP_NORTP) == 0) {
|
||||||
|
globpath(p_rtp, tail, gap, glob_flags, expand_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & DIP_START) {
|
||||||
|
memcpy(tail - 15, "pack/*/start/*/", 15); // NOLINT
|
||||||
|
globpath(p_pp, tail - 15, gap, glob_flags, expand_dirs);
|
||||||
|
memcpy(tail - 8, "start/*/", 8); // NOLINT
|
||||||
|
globpath(p_pp, tail - 8, gap, glob_flags, expand_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & DIP_OPT) {
|
||||||
|
memcpy(tail - 13, "pack/*/opt/*/", 13); // NOLINT
|
||||||
|
globpath(p_pp, tail - 13, gap, glob_flags, expand_dirs);
|
||||||
|
memcpy(tail - 6, "opt/*/", 6); // NOLINT
|
||||||
|
globpath(p_pp, tail - 6, gap, glob_flags, expand_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*dirnames[i] == NUL && !expand_dirs) {
|
||||||
|
// expand dir names in another round
|
||||||
|
snprintf(tail, tail_buflen, "%s*", pat);
|
||||||
|
glob_flags = WILD_ADD_SLASH;
|
||||||
|
expand_dirs = true;
|
||||||
|
goto expand;
|
||||||
|
}
|
||||||
|
|
||||||
|
xfree(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pat_pathsep_cnt = 0;
|
||||||
|
for (size_t i = 0; i < pat_len; i++) {
|
||||||
|
if (vim_ispathsep(pat[i])) {
|
||||||
|
pat_pathsep_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < gap->ga_len; i++) {
|
||||||
|
char *match = ((char **)gap->ga_data)[i];
|
||||||
|
char *s = match;
|
||||||
|
char *e = s + strlen(s);
|
||||||
|
if (e - s > 4 && !keep_ext && (STRNICMP(e - 4, ".vim", 4) == 0
|
||||||
|
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
|
||||||
|
e -= 4;
|
||||||
|
*e = NUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int match_pathsep_cnt = (e > s && e[-1] == '/') ? -1 : 0;
|
||||||
|
for (s = e; s > match; MB_PTR_BACK(match, s)) {
|
||||||
|
if (vim_ispathsep(*s) && ++match_pathsep_cnt > pat_pathsep_cnt) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
if (s != match) {
|
||||||
|
assert((e - s) + 1 >= 0);
|
||||||
|
memmove(match, s, (size_t)(e - s) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GA_EMPTY(gap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort and remove duplicates which can happen when specifying multiple
|
||||||
|
// directories in dirnames.
|
||||||
|
ga_remove_duplicate_strings(gap);
|
||||||
|
}
|
||||||
|
|
||||||
/// Expand color scheme, compiler or filetype names.
|
/// Expand color scheme, compiler or filetype names.
|
||||||
/// Search from 'runtimepath':
|
/// Search from 'runtimepath':
|
||||||
/// 'runtimepath'/{dirnames}/{pat}.(vim|lua)
|
/// 'runtimepath'/{dirnames}/{pat}.(vim|lua)
|
||||||
@ -1187,72 +1302,41 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
|||||||
{
|
{
|
||||||
*num_file = 0;
|
*num_file = 0;
|
||||||
*file = NULL;
|
*file = NULL;
|
||||||
size_t pat_len = strlen(pat);
|
|
||||||
|
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
ga_init(&ga, (int)sizeof(char *), 10);
|
ga_init(&ga, (int)sizeof(char *), 10);
|
||||||
|
|
||||||
// TODO(bfredl): this is bullshit, expandpath should not reinvent path logic.
|
ExpandRTDir_int(pat, strlen(pat), flags, false, &ga, dirnames);
|
||||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
|
||||||
size_t size = strlen(dirnames[i]) + pat_len + 16;
|
if (GA_EMPTY(&ga)) {
|
||||||
char *s = xmalloc(size);
|
return FAIL;
|
||||||
snprintf(s, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
|
|
||||||
globpath(p_rtp, s, &ga, 0);
|
|
||||||
xfree(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DIP_START) {
|
*file = ga.ga_data;
|
||||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
*num_file = ga.ga_len;
|
||||||
size_t size = strlen(dirnames[i]) + pat_len + 31;
|
return OK;
|
||||||
char *s = xmalloc(size);
|
}
|
||||||
snprintf(s, size, "pack/*/start/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT
|
|
||||||
globpath(p_pp, s, &ga, 0);
|
|
||||||
xfree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
/// Handle command line completion for :runtime command.
|
||||||
size_t size = strlen(dirnames[i]) + pat_len + 31;
|
int expand_runtime_cmd(char *pat, int *numMatches, char ***matches)
|
||||||
char *s = xmalloc(size);
|
{
|
||||||
snprintf(s, size, "start/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT
|
*numMatches = 0;
|
||||||
globpath(p_pp, s, &ga, 0);
|
*matches = NULL;
|
||||||
xfree(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & DIP_OPT) {
|
garray_T ga;
|
||||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
ga_init(&ga, sizeof(char *), 10);
|
||||||
size_t size = strlen(dirnames[i]) + pat_len + 29;
|
|
||||||
char *s = xmalloc(size);
|
|
||||||
snprintf(s, size, "pack/*/opt/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT
|
|
||||||
globpath(p_pp, s, &ga, 0);
|
|
||||||
xfree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; dirnames[i] != NULL; i++) {
|
const size_t pat_len = strlen(pat);
|
||||||
size_t size = strlen(dirnames[i]) + pat_len + 29;
|
char *dirnames[] = { "", NULL };
|
||||||
char *s = xmalloc(size);
|
ExpandRTDir_int(pat, pat_len, runtime_expand_flags, true, &ga, dirnames);
|
||||||
snprintf(s, size, "opt/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT
|
|
||||||
globpath(p_pp, s, &ga, 0);
|
|
||||||
xfree(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < ga.ga_len; i++) {
|
// Try to complete values for [where] argument when none was found.
|
||||||
char *match = ((char **)ga.ga_data)[i];
|
if (runtime_expand_flags == 0) {
|
||||||
char *s = match;
|
char *where_values[] = { "START", "OPT", "PACK", "ALL" };
|
||||||
char *e = s + strlen(s);
|
for (size_t i = 0; i < ARRAY_SIZE(where_values); i++) {
|
||||||
if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
|
if (strncmp(pat, where_values[i], pat_len) == 0) {
|
||||||
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
|
GA_APPEND(char *, &ga, xstrdup(where_values[i]));
|
||||||
e -= 4;
|
|
||||||
for (s = e; s > match; MB_PTR_BACK(match, s)) {
|
|
||||||
if (vim_ispathsep(*s)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s++;
|
|
||||||
*e = NUL;
|
|
||||||
assert((e - s) + 1 >= 0);
|
|
||||||
memmove(match, s, (size_t)(e - s) + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1260,17 +1344,13 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort and remove duplicates which can happen when specifying multiple
|
*matches = ga.ga_data;
|
||||||
// directories in dirnames.
|
*numMatches = ga.ga_len;
|
||||||
ga_remove_duplicate_strings(&ga);
|
|
||||||
|
|
||||||
*file = ga.ga_data;
|
|
||||||
*num_file = ga.ga_len;
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expand loadplugin names:
|
/// Expand loadplugin names:
|
||||||
/// 'packpath'/pack/ * /opt/{pat}
|
/// 'packpath'/pack/*/opt/{pat}
|
||||||
int ExpandPackAddDir(char *pat, int *num_file, char ***file)
|
int ExpandPackAddDir(char *pat, int *num_file, char ***file)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -1283,9 +1363,9 @@ int ExpandPackAddDir(char *pat, int *num_file, char ***file)
|
|||||||
size_t buflen = pat_len + 26;
|
size_t buflen = pat_len + 26;
|
||||||
char *s = xmalloc(buflen);
|
char *s = xmalloc(buflen);
|
||||||
snprintf(s, buflen, "pack/*/opt/%s*", pat); // NOLINT
|
snprintf(s, buflen, "pack/*/opt/%s*", pat); // NOLINT
|
||||||
globpath(p_pp, s, &ga, 0);
|
globpath(p_pp, s, &ga, 0, true);
|
||||||
snprintf(s, buflen, "opt/%s*", pat); // NOLINT
|
snprintf(s, buflen, "opt/%s*", pat); // NOLINT
|
||||||
globpath(p_pp, s, &ga, 0);
|
globpath(p_pp, s, &ga, 0, true);
|
||||||
xfree(s);
|
xfree(s);
|
||||||
|
|
||||||
for (int i = 0; i < ga.ga_len; i++) {
|
for (int i = 0; i < ga.ga_len; i++) {
|
||||||
|
@ -26,7 +26,7 @@ func Test_packadd()
|
|||||||
|
|
||||||
let rtp_entries = split(rtp, ',')
|
let rtp_entries = split(rtp, ',')
|
||||||
for entry in rtp_entries
|
for entry in rtp_entries
|
||||||
if entry =~? '\<after\>'
|
if entry =~? '\<after\>'
|
||||||
let first_after_entry = entry
|
let first_after_entry = entry
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
@ -186,15 +186,17 @@ func Test_packadd_symlink_dir2()
|
|||||||
exec "silent !rmdir" top2_dir
|
exec "silent !rmdir" top2_dir
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Check command-line completion for 'packadd'
|
" Check command-line completion for :packadd
|
||||||
func Test_packadd_completion()
|
func Test_packadd_completion()
|
||||||
let optdir1 = &packpath . '/pack/mine/opt'
|
let optdir1 = &packpath . '/pack/mine/opt'
|
||||||
let optdir2 = &packpath . '/pack/candidate/opt'
|
let optdir2 = &packpath . '/pack/candidate/opt'
|
||||||
|
|
||||||
call mkdir(optdir1 . '/pluginA', 'p')
|
call mkdir(optdir1 . '/pluginA', 'p')
|
||||||
call mkdir(optdir1 . '/pluginC', 'p')
|
call mkdir(optdir1 . '/pluginC', 'p')
|
||||||
|
call writefile([], optdir1 . '/unrelated')
|
||||||
call mkdir(optdir2 . '/pluginB', 'p')
|
call mkdir(optdir2 . '/pluginB', 'p')
|
||||||
call mkdir(optdir2 . '/pluginC', 'p')
|
call mkdir(optdir2 . '/pluginC', 'p')
|
||||||
|
call writefile([], optdir2 . '/unrelated')
|
||||||
|
|
||||||
let li = []
|
let li = []
|
||||||
call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
|
call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
|
||||||
@ -260,9 +262,9 @@ func Test_helptags()
|
|||||||
|
|
||||||
helptags ALL
|
helptags ALL
|
||||||
|
|
||||||
let tags1 = readfile(docdir1 . '/tags')
|
let tags1 = readfile(docdir1 . '/tags')
|
||||||
call assert_match('look-here', tags1[0])
|
call assert_match('look-here', tags1[0])
|
||||||
let tags2 = readfile(docdir2 . '/tags')
|
let tags2 = readfile(docdir2 . '/tags')
|
||||||
call assert_match('look-away', tags2[0])
|
call assert_match('look-away', tags2[0])
|
||||||
|
|
||||||
call assert_fails('helptags abcxyz', 'E150:')
|
call assert_fails('helptags abcxyz', 'E150:')
|
||||||
@ -358,4 +360,78 @@ func Test_runtime()
|
|||||||
call assert_equal('runstartopt', g:sequence)
|
call assert_equal('runstartopt', g:sequence)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_runtime_completion()
|
||||||
|
let rundir = &packpath . '/runtime/Aextra'
|
||||||
|
let startdir = &packpath . '/pack/mine/start/foo/Aextra'
|
||||||
|
let optdir = &packpath . '/pack/mine/opt/bar/Aextra'
|
||||||
|
call mkdir(rundir . '/Arunbaz', 'p')
|
||||||
|
call mkdir(startdir . '/Astartbaz', 'p')
|
||||||
|
call mkdir(optdir . '/Aoptbaz', 'p')
|
||||||
|
call writefile([], rundir . '/../Arunfoo.vim')
|
||||||
|
call writefile([], rundir . '/Arunbar.vim')
|
||||||
|
call writefile([], rundir . '/Aunrelated')
|
||||||
|
call writefile([], rundir . '/../Aunrelated')
|
||||||
|
call writefile([], startdir . '/../Astartfoo.vim')
|
||||||
|
call writefile([], startdir . '/Astartbar.vim')
|
||||||
|
call writefile([], startdir . '/Aunrelated')
|
||||||
|
call writefile([], startdir . '/../Aunrelated')
|
||||||
|
call writefile([], optdir . '/../Aoptfoo.vim')
|
||||||
|
call writefile([], optdir . '/Aoptbar.vim')
|
||||||
|
call writefile([], optdir . '/Aunrelated')
|
||||||
|
call writefile([], optdir . '/../Aunrelated')
|
||||||
|
exe 'set rtp=' . &packpath . '/runtime'
|
||||||
|
|
||||||
|
func Check_runtime_completion(arg, arg1, res)
|
||||||
|
call feedkeys(':runtime ' .. a:arg .. "\<C-A>\<C-B>\"\<CR>", 'xt')
|
||||||
|
call assert_equal('"runtime ' .. a:arg1 .. join(a:res), @:)
|
||||||
|
call assert_equal(a:res, getcompletion(a:arg, 'runtime'))
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
call Check_runtime_completion('', '',
|
||||||
|
\ ['Aextra/', 'Arunfoo.vim', 'START', 'OPT', 'PACK', 'ALL'])
|
||||||
|
call Check_runtime_completion('S', '',
|
||||||
|
\ ['START'])
|
||||||
|
call Check_runtime_completion('O', '',
|
||||||
|
\ ['OPT'])
|
||||||
|
call Check_runtime_completion('P', '',
|
||||||
|
\ ['PACK'])
|
||||||
|
call Check_runtime_completion('A', '',
|
||||||
|
\ ['Aextra/', 'Arunfoo.vim', 'ALL'])
|
||||||
|
call Check_runtime_completion('Aextra/', '',
|
||||||
|
\ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
|
||||||
|
|
||||||
|
call Check_runtime_completion('START ', 'START ',
|
||||||
|
\ ['Aextra/', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('START A', 'START ',
|
||||||
|
\ ['Aextra/', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('START Aextra/', 'START ',
|
||||||
|
\ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
|
||||||
|
|
||||||
|
call Check_runtime_completion('OPT ', 'OPT ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim'])
|
||||||
|
call Check_runtime_completion('OPT A', 'OPT ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim'])
|
||||||
|
call Check_runtime_completion('OPT Aextra/', 'OPT ',
|
||||||
|
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
|
||||||
|
|
||||||
|
call Check_runtime_completion('PACK ', 'PACK ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('PACK A', 'PACK ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('PACK Aextra/', 'PACK ',
|
||||||
|
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
|
||||||
|
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
|
||||||
|
|
||||||
|
call Check_runtime_completion('ALL ', 'ALL ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('ALL A', 'ALL ',
|
||||||
|
\ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
|
||||||
|
call Check_runtime_completion('ALL Aextra/', 'ALL ',
|
||||||
|
\ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
|
||||||
|
\ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
|
||||||
|
\ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
|
||||||
|
|
||||||
|
delfunc Check_runtime_completion
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -89,6 +89,7 @@ static const char *command_complete[] = {
|
|||||||
[EXPAND_SYNTIME] = "syntime",
|
[EXPAND_SYNTIME] = "syntime",
|
||||||
[EXPAND_SETTINGS] = "option",
|
[EXPAND_SETTINGS] = "option",
|
||||||
[EXPAND_PACKADD] = "packadd",
|
[EXPAND_PACKADD] = "packadd",
|
||||||
|
[EXPAND_RUNTIME] = "runtime",
|
||||||
[EXPAND_SHELLCMD] = "shellcmd",
|
[EXPAND_SHELLCMD] = "shellcmd",
|
||||||
[EXPAND_SIGN] = "sign",
|
[EXPAND_SIGN] = "sign",
|
||||||
[EXPAND_TAGS] = "tag",
|
[EXPAND_TAGS] = "tag",
|
||||||
|
@ -156,6 +156,7 @@ enum {
|
|||||||
EXPAND_DIFF_BUFFERS,
|
EXPAND_DIFF_BUFFERS,
|
||||||
EXPAND_BREAKPOINT,
|
EXPAND_BREAKPOINT,
|
||||||
EXPAND_SCRIPTNAMES,
|
EXPAND_SCRIPTNAMES,
|
||||||
|
EXPAND_RUNTIME,
|
||||||
EXPAND_CHECKHEALTH,
|
EXPAND_CHECKHEALTH,
|
||||||
EXPAND_LUA,
|
EXPAND_LUA,
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@ 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')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
teardown(function()
|
teardown(function()
|
||||||
@ -42,6 +43,7 @@ describe('runtime:', function()
|
|||||||
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
||||||
|
|
||||||
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
|
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
|
||||||
|
eq({'colors/new_colorscheme.lua'}, funcs.getcompletion('colors/new_c', 'runtime'))
|
||||||
|
|
||||||
exec('colorscheme new_colorscheme')
|
exec('colorscheme new_colorscheme')
|
||||||
|
|
||||||
@ -71,6 +73,7 @@ describe('runtime:', function()
|
|||||||
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
|
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
|
||||||
|
|
||||||
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
|
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
|
||||||
|
eq({'compiler/new_compiler.lua'}, funcs.getcompletion('compiler/new_c', 'runtime'))
|
||||||
|
|
||||||
exec('compiler new_compiler')
|
exec('compiler new_compiler')
|
||||||
|
|
||||||
@ -100,6 +103,7 @@ describe('runtime:', function()
|
|||||||
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
|
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
|
||||||
|
|
||||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||||
|
eq({'ftplugin/new-ft.lua'}, funcs.getcompletion('ftplugin/new-f', 'runtime'))
|
||||||
|
|
||||||
exec [[set filetype=new-ft]]
|
exec [[set filetype=new-ft]]
|
||||||
eq(1, eval('b:lua_ftplugin'))
|
eq(1, eval('b:lua_ftplugin'))
|
||||||
@ -116,6 +120,7 @@ describe('runtime:', function()
|
|||||||
write_file(indent_file , [[vim.b.lua_indent = 1]])
|
write_file(indent_file , [[vim.b.lua_indent = 1]])
|
||||||
|
|
||||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||||
|
eq({'indent/new-ft.lua'}, funcs.getcompletion('indent/new-f', 'runtime'))
|
||||||
|
|
||||||
exec [[set filetype=new-ft]]
|
exec [[set filetype=new-ft]]
|
||||||
eq(1, eval('b:lua_indent'))
|
eq(1, eval('b:lua_indent'))
|
||||||
@ -152,6 +157,7 @@ describe('runtime:', function()
|
|||||||
it('lua syntaxes are included in cmdline completion', function()
|
it('lua syntaxes are included in cmdline completion', function()
|
||||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
|
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
|
||||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
|
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
|
||||||
|
eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user