aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_cmds2.c29
-rw-r--r--test/functional/legacy/packadd_spec.lua23
2 files changed, 44 insertions, 8 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index f07bc0e137..120278d3fb 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -2693,14 +2693,27 @@ void ex_packloadall(exarg_T *eap)
/// ":packadd[!] {name}"
void ex_packadd(exarg_T *eap)
{
- static const char *plugpat = "pack/*/opt/%s"; // NOLINT
-
- size_t len = STRLEN(plugpat) + STRLEN(eap->arg);
- char *pat = (char *)xmallocz(len);
- vim_snprintf(pat, len, plugpat, eap->arg);
- do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR, add_pack_plugin,
- eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
- xfree(pat);
+ static const char *plugpat = "pack/*/%s/%s"; // NOLINT
+ int res = OK;
+
+ // Round 1: use "start", round 2: use "opt".
+ for (int round = 1; round <= 2; round++) {
+ // Only look under "start" when loading packages wasn't done yet.
+ if (round == 1 && did_source_packages) {
+ continue;
+ }
+
+ const size_t len = STRLEN(plugpat) + STRLEN(eap->arg) + 5;
+ char *pat = xmallocz(len);
+ vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
+ // The first round don't give a "not found" error, in the second round
+ // only when nothing was found in the first round.
+ res = do_in_path(p_pp, (char_u *)pat,
+ DIP_ALL + DIP_DIR
+ + (round == 2 && res == FAIL ? DIP_ERR : 0),
+ add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
+ xfree(pat);
+ }
}
/// ":options"
diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua
index fb308475c0..67f6006d1d 100644
--- a/test/functional/legacy/packadd_spec.lua
+++ b/test/functional/legacy/packadd_spec.lua
@@ -58,6 +58,24 @@ describe('packadd', function()
call assert_fails("packadd", 'E471:')
endfunc
+ func Test_packadd_start()
+ let plugdir = expand(s:topdir . '/pack/mine/start/other')
+ call mkdir(plugdir . '/plugin', 'p')
+ set rtp&
+ let rtp = &rtp
+ filetype on
+
+ exe 'split ' . plugdir . '/plugin/test.vim'
+ call setline(1, 'let g:plugin_works = 24')
+ wq
+
+ packadd other
+
+ call assert_equal(24, g:plugin_works)
+ call assert_true(len(&rtp) > len(rtp))
+ call assert_true(&rtp =~ (escape(plugdir, '\') . '\($\|,\)'))
+ endfunc
+
func Test_packadd_noload()
call mkdir(s:plugdir . '/plugin', 'p')
call mkdir(s:plugdir . '/syntax', 'p')
@@ -286,6 +304,11 @@ describe('packadd', function()
expected_empty()
end)
+ it('loads packages from "start" directory', function()
+ call('Test_packadd_start')
+ expected_empty()
+ end)
+
describe('command line completion', function()
local Screen = require('test.functional.ui.screen')
local screen