diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-09-11 20:11:16 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-09-18 13:59:19 +0200 |
commit | a860f7880fd5d5cef5299ff8d450ac037bee2300 (patch) | |
tree | b929329658316d6a8a7aead01f0b701c0e278fca | |
parent | 396280d3030685c6b7c4d962f24bb5171a735b47 (diff) | |
download | rneovim-a860f7880fd5d5cef5299ff8d450ac037bee2300.tar.gz rneovim-a860f7880fd5d5cef5299ff8d450ac037bee2300.tar.bz2 rneovim-a860f7880fd5d5cef5299ff8d450ac037bee2300.zip |
refactor(runtime): handle pack/foo/start/bar/after dirs properly
The order should be:
XDG_CONFIG_HOME/nvim
XDG_DATA_HOME/nvim/site/pack/foo/start/bar/
XDG_CONFIG_HOME/nvim/after
XDG_DATA_HOME/nvim/site/pack/foo/start/bar/after
8 files changed, 58 insertions, 12 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 64aa653b6a..d4191cff6b 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -168,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 && !*name) ? NULL : 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); + 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); } diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 861889e7fc..f057420dde 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -310,7 +310,7 @@ describe('startup', function() end) local function pack_clear(cmd) - clear('--cmd', 'set packpath=test/functional/fixtures', '--cmd', cmd) + clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} end @@ -348,6 +348,16 @@ describe('startup', function() pack_clear [[ packadd! bonus | lua _G.y = require'bonus'.launch() ]] eq('CPE 1704 TKS', exec_lua [[ return _G.y ]]) end) + + it("handles the correct order with start packages and after/", function() + pack_clear [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]] + eq({'ordinary', 'FANCY', 'ordinary after', 'FANCY after'}, exec_lua [[ return _G.test_loadorder ]]) + end) + + it("handles the correct order with opt packages and after/", function() + pack_clear [[ lua _G.test_loadorder = {} vim.cmd "packadd! superspecial\nruntime! filen.lua" ]] + eq({'ordinary', 'SuperSpecial', 'FANCY', 'SuperSpecial after', 'ordinary after', 'FANCY after'}, exec_lua [[ return _G.test_loadorder ]]) + end) end) describe('sysinit', function() @@ -504,6 +514,7 @@ describe('runtime:', function() local xenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } setup(function() + rmdir(xhome) mkdir_p(xconfig .. pathsep .. 'nvim') mkdir_p(xdata) end) @@ -524,7 +535,7 @@ describe('runtime:', function() rmdir(plugin_folder_path) end) - it('loads plugin/*.lua from start plugins', function() + it('loads plugin/*.lua from start packages', function() local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', 'start', 'test_plugin'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) @@ -552,6 +563,27 @@ describe('runtime:', function() rmdir(plugin_path) end) + it('loads plugin/*.lua from site packages', function() + local nvimdata = iswin() and "nvim-data" or "nvim" + local plugin_path = table.concat({xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb'}, pathsep) + local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) + local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep) + local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) + local plugin_after_file_path = table.concat({plugin_after_path, 'helloo.lua'}, pathsep) + + mkdir_p(plugin_folder_path) + write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]]) + mkdir_p(plugin_after_path) + write_file(plugin_after_file_path, [[table.insert(_G.lista, "dos")]]) + + clear{ args_rm={'-u'}, args={'--cmd', 'lua _G.lista = {}'}, env=xenv } + + eq({'unos', 'dos'}, exec_lua "return _G.lista") + + rmdir(plugin_path) + end) + + it('loads ftdetect/*.lua', function() local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep) diff --git a/test/functional/fixtures/nvim/after/filen.lua b/test/functional/fixtures/nvim/after/filen.lua new file mode 100644 index 0000000000..0128a0a16a --- /dev/null +++ b/test/functional/fixtures/nvim/after/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "ordinary after") diff --git a/test/functional/fixtures/nvim/filen.lua b/test/functional/fixtures/nvim/filen.lua new file mode 100644 index 0000000000..e2bd5e8f7f --- /dev/null +++ b/test/functional/fixtures/nvim/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "ordinary") diff --git a/test/functional/fixtures/pack/foo/opt/superspecial/after/filen.lua b/test/functional/fixtures/pack/foo/opt/superspecial/after/filen.lua new file mode 100644 index 0000000000..94bf6850b2 --- /dev/null +++ b/test/functional/fixtures/pack/foo/opt/superspecial/after/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "SuperSpecial after") diff --git a/test/functional/fixtures/pack/foo/opt/superspecial/filen.lua b/test/functional/fixtures/pack/foo/opt/superspecial/filen.lua new file mode 100644 index 0000000000..cbaab1a45a --- /dev/null +++ b/test/functional/fixtures/pack/foo/opt/superspecial/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "SuperSpecial") diff --git a/test/functional/fixtures/pack/foo/start/fancyplugin/after/filen.lua b/test/functional/fixtures/pack/foo/start/fancyplugin/after/filen.lua new file mode 100644 index 0000000000..9beac762ee --- /dev/null +++ b/test/functional/fixtures/pack/foo/start/fancyplugin/after/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "FANCY after") diff --git a/test/functional/fixtures/pack/foo/start/fancyplugin/filen.lua b/test/functional/fixtures/pack/foo/start/fancyplugin/filen.lua new file mode 100644 index 0000000000..34e4b9c95e --- /dev/null +++ b/test/functional/fixtures/pack/foo/start/fancyplugin/filen.lua @@ -0,0 +1 @@ +table.insert(_G.test_loadorder, "FANCY") |