mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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)
|
||||
|
1
test/functional/fixtures/nvim/after/filen.lua
Normal file
1
test/functional/fixtures/nvim/after/filen.lua
Normal file
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "ordinary after")
|
1
test/functional/fixtures/nvim/filen.lua
Normal file
1
test/functional/fixtures/nvim/filen.lua
Normal file
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "ordinary")
|
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "SuperSpecial after")
|
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "SuperSpecial")
|
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "FANCY after")
|
@@ -0,0 +1 @@
|
||||
table.insert(_G.test_loadorder, "FANCY")
|
Reference in New Issue
Block a user