diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-09-18 17:14:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-18 17:14:25 +0200 |
commit | 6cad86fffdb91d3997a707ff6adb0b5991587b3e (patch) | |
tree | b929329658316d6a8a7aead01f0b701c0e278fca /src | |
parent | 8ef2b56cac895c151345cf0ff0a97456c0a7fdd2 (diff) | |
parent | a860f7880fd5d5cef5299ff8d450ac037bee2300 (diff) | |
download | rneovim-6cad86fffdb91d3997a707ff6adb0b5991587b3e.tar.gz rneovim-6cad86fffdb91d3997a707ff6adb0b5991587b3e.tar.bz2 rneovim-6cad86fffdb91d3997a707ff6adb0b5991587b3e.zip |
Merge pull request #15632 from bfredl/rtptest
runtime: always use DIP_START and remove duplication of start packages in &rtp
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 51 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 4 | ||||
-rw-r--r-- | src/nvim/main.c | 21 | ||||
-rw-r--r-- | src/nvim/runtime.c | 62 | ||||
-rw-r--r-- | src/nvim/syntax.c | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_startup.vim | 2 | ||||
-rw-r--r-- | src/nvim/vim.h | 1 |
7 files changed, 41 insertions, 102 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f65d5cc185..e764c45f0e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -750,47 +750,10 @@ Integer nvim_strwidth(String text, Error *err) /// Gets the paths contained in 'runtimepath'. /// /// @return List of paths -ArrayOf(String) nvim_list_runtime_paths(void) +ArrayOf(String) nvim_list_runtime_paths(Error *err) FUNC_API_SINCE(1) { - // TODO(bfredl): this should just work: - // return nvim_get_runtime_file(NULL_STRING, true); - - Array rv = ARRAY_DICT_INIT; - - char_u *rtp = p_rtp; - - if (*rtp == NUL) { - // No paths - return rv; - } - - // Count the number of paths in rtp - while (*rtp != NUL) { - if (*rtp == ',') { - rv.size++; - } - rtp++; - } - rv.size++; - - // Allocate memory for the copies - rv.items = xmalloc(sizeof(*rv.items) * rv.size); - // Reset the position - rtp = p_rtp; - // Start copying - for (size_t i = 0; i < rv.size; i++) { - rv.items[i].type = kObjectTypeString; - rv.items[i].data.string.data = xmalloc(MAXPATHL); - // Copy the path from 'runtimepath' to rv.items[i] - size_t length = copy_option_part(&rtp, - (char_u *)rv.items[i].data.string.data, - MAXPATHL, - ","); - rv.items[i].data.string.size = length; - } - - return rv; + return nvim_get_runtime_file(NULL_STRING, true, err); } /// Find files in runtime directories @@ -802,10 +765,6 @@ ArrayOf(String) nvim_list_runtime_paths(void) /// /// It is not an error to not find any files. An empty array is returned then. /// -/// To find a directory, `name` must end with a forward slash, like -/// "rplugin/python/". Without the slash it would instead look for an ordinary -/// file called "rplugin/python". -/// /// @param name pattern of files to search for /// @param all whether to return all matches or only the first /// @return list of absolute paths to the found files @@ -815,11 +774,7 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Error *err) { Array rv = ARRAY_DICT_INIT; - int flags = DIP_START | (all ? DIP_ALL : 0); - - if (name.size == 0 || name.data[name.size-1] == '/') { - flags |= DIP_DIR; - } + int flags = DIP_DIRFILE | (all ? DIP_ALL : 0); do_in_runtimepath((char_u *)(name.size ? name.data : ""), flags, find_runtime_cb, &rv); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 6542ab41f5..575c5c9cbd 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1641,10 +1641,10 @@ void ex_compiler(exarg_T *eap) do_unlet(S_LEN("b:current_compiler"), true); snprintf((char *)buf, bufsize, "compiler/%s.vim", eap->arg); - if (source_in_path(p_rtp, buf, DIP_ALL) == FAIL) { + if (source_runtime(buf, DIP_ALL) == FAIL) { // Try lua compiler snprintf((char *)buf, bufsize, "compiler/%s.lua", eap->arg); - if (source_in_path(p_rtp, buf, DIP_ALL) == FAIL) { + if (source_runtime(buf, DIP_ALL) == FAIL) { EMSG2(_("E666: compiler not supported: %s"), eap->arg); } } diff --git a/src/nvim/main.c b/src/nvim/main.c index 1fc140e525..1507dfac00 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1352,23 +1352,10 @@ static void load_plugins(void) char_u *const plugin_pattern_vim = (char_u *)"plugin/**/*.vim"; // NOLINT char_u *const plugin_pattern_lua = (char_u *)"plugin/**/*.lua"; // NOLINT - // First add all package directories to 'runtimepath', so that their - // autoload directories can be found. Only if not done already with a - // :packloadall command. - // Make a copy of 'runtimepath', so that source_runtime does not use the - // pack directories. - if (!did_source_packages) { - rtp_copy = vim_strsave(p_rtp); - add_pack_start_dirs(); - } - - source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy, - plugin_pattern_vim, - DIP_ALL | DIP_NOAFTER); - source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy, - plugin_pattern_lua, - DIP_ALL | DIP_NOAFTER); - TIME_MSG("loading plugins"); + // don't use source_runtime() yet so we can check for :packloadall below + source_in_path(p_rtp, plugin_pattern_vim, DIP_ALL | DIP_NOAFTER); + source_in_path(p_rtp, plugin_pattern_lua, DIP_ALL | DIP_NOAFTER); + TIME_MSG("loading rtp plugins"); xfree(rtp_copy); // Only source "start" packages if not done already with a :packloadall diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 4da81f29e3..d4191cff6b 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -100,10 +100,8 @@ int do_in_path(char_u *path, char_u *name, int flags, } if (name == NULL) { - (*callback)(buf, (void *)&cookie); - if (!did_one) { - did_one = (cookie == NULL); - } + (*callback)(buf, cookie); + did_one = true; } else if (buflen + STRLEN(name) + 2 < MAXPATHL) { add_pathsep((char *)buf); tail = buf + STRLEN(buf); @@ -122,10 +120,11 @@ int do_in_path(char_u *path, char_u *name, int flags, verbose_leave(); } + int ew_flags = ((flags & DIP_DIR) ? EW_DIR : EW_FILE) + | (flags & DIP_DIRFILE) ? (EW_DIR|EW_FILE) : 0; + // Expand wildcards, invoke the callback for each match. - if (gen_expand_wildcards(1, &buf, &num_files, &files, - (flags & DIP_DIR) ? EW_DIR : EW_FILE) - == OK) { + if (gen_expand_wildcards(1, &buf, &num_files, &files, ew_flags) == OK) { for (i = 0; i < num_files; i++) { (*callback)(files[i], cookie); did_one = true; @@ -169,28 +168,36 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB callback, void *cookie) { int done = FAIL; + if (!(flags & (DIP_NOAFTER | DIP_AFTER))) { + done = do_in_path_and_pp(path, name, flags | DIP_NOAFTER, callback, cookie); + if (done == OK && !(flags & DIP_ALL)) { + return done; + } + flags |= DIP_AFTER; + } if ((flags & DIP_NORTP) == 0) { - done = do_in_path(path, name, flags, callback, cookie); + done |= do_in_path(path, (name && !*name) ? NULL : name, flags, callback, cookie); } if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) { - char *start_dir = "pack/*/start/*/%s"; // NOLINT - size_t len = STRLEN(start_dir) + STRLEN(name); - char_u *s = xmallocz(len); + char *start_dir = "pack/*/start/*/%s%s"; // NOLINT + size_t len = STRLEN(start_dir) + STRLEN(name) + 6; + char_u *s = xmallocz(len); // TODO(bfredl): get rid of random allocations + char *suffix = (flags & DIP_AFTER) ? "after/" : ""; - vim_snprintf((char *)s, len, start_dir, name); - done = do_in_path(p_pp, s, flags, callback, cookie); + vim_snprintf((char *)s, len, start_dir, suffix, name); + done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie); xfree(s); - if (done == FAIL|| (flags & DIP_ALL)) { - start_dir = "start/*/%s"; // NOLINT - len = STRLEN(start_dir) + STRLEN(name); + if (done == FAIL || (flags & DIP_ALL)) { + start_dir = "start/*/%s%s"; // NOLINT + len = STRLEN(start_dir) + STRLEN(name) + 6; s = xmallocz(len); - vim_snprintf((char *)s, len, start_dir, name); - done = do_in_path(p_pp, s, flags, callback, cookie); + vim_snprintf((char *)s, len, start_dir, suffix, name); + done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie); xfree(s); } @@ -202,7 +209,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, char_u *s = xmallocz(len); vim_snprintf((char *)s, len, opt_dir, name); - done = do_in_path(p_pp, s, flags, callback, cookie); + done |= do_in_path(p_pp, s, flags, callback, cookie); xfree(s); @@ -212,7 +219,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, s = xmallocz(len); vim_snprintf((char *)s, len, opt_dir, name); - done = do_in_path(p_pp, s, flags, callback, cookie); + done |= do_in_path(p_pp, s, flags, callback, cookie); xfree(s); } @@ -222,10 +229,9 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, } /// Just like do_in_path_and_pp(), using 'runtimepath' for "path". -int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, - void *cookie) +int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, void *cookie) { - return do_in_path_and_pp(p_rtp, name, flags, callback, cookie); + return do_in_path_and_pp(p_rtp, name, flags | DIP_START, callback, cookie); } /// Source the file "name" from all directories in 'runtimepath'. @@ -481,15 +487,6 @@ static void add_opt_pack_plugin(char_u *fname, void *cookie) add_pack_plugin(true, fname, cookie); } -/// Add all packages in the "start" directory to 'runtimepath'. -void add_pack_start_dirs(void) -{ - do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT - add_start_pack_plugin, &APP_ADD_DIR); - do_in_path(p_pp, (char_u *)"start/*", DIP_ALL + DIP_DIR, // NOLINT - add_start_pack_plugin, &APP_ADD_DIR); -} - /// Load plugins from all packages in the "start" directory. void load_start_packages(void) { @@ -508,7 +505,6 @@ void ex_packloadall(exarg_T *eap) // First do a round to add all directories to 'runtimepath', then load // the plugins. This allows for plugins to use an autoload directory // of another plugin. - add_pack_start_dirs(); load_start_packages(); } } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 2512495a0a..10cc2ea9b8 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4394,7 +4394,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) curwin->w_s->b_syn_topgrp = sgl_id; if (source ? do_source(eap->arg, false, DOSO_NONE) == FAIL - : source_in_path(p_rtp, eap->arg, DIP_ALL) == FAIL) { + : source_runtime(eap->arg, DIP_ALL) == FAIL) { EMSG2(_(e_notopen), eap->arg); } curwin->w_s->b_syn_topgrp = prev_toplvl_grp; diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index e0dc0e0075..daebe25466 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -102,7 +102,7 @@ func Test_pack_in_rtp_when_plugins_run() if RunVim(before, after, '') let lines = filter(readfile('Xtestout'), '!empty(v:val)') - call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) + call assert_match('runtimepath=Xhere', get(lines, 0)) call assert_match('autoloaded foo', get(lines, 1)) endif diff --git a/src/nvim/vim.h b/src/nvim/vim.h index d84979f6fe..f61f9a5e01 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -315,6 +315,7 @@ enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext() #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 // Lowest number used for window ID. Cannot have this many windows per tab. #define LOWEST_WIN_ID 1000 |