mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
fix: runtimepath always updates lua package.path
This commit is contained in:
@@ -543,6 +543,14 @@ static lua_State *nlua_enter(void)
|
||||
return lstate;
|
||||
}
|
||||
|
||||
/// Force an update of lua's package paths if runtime path has changed.
|
||||
bool nlua_update_package_path(void)
|
||||
{
|
||||
lua_State *const lstate = nlua_enter();
|
||||
|
||||
return !!lstate;
|
||||
}
|
||||
|
||||
static void nlua_print_event(void **argv)
|
||||
{
|
||||
char *str = argv[0];
|
||||
|
@@ -80,6 +80,7 @@
|
||||
#ifdef WIN32
|
||||
# include "nvim/os/pty_conpty_win.h"
|
||||
#endif
|
||||
#include "nvim/lua/executor.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/os/input.h"
|
||||
#include "nvim/os/lang.h"
|
||||
@@ -3344,6 +3345,10 @@ ambw_end:
|
||||
if (!parse_winhl_opt(curwin)) {
|
||||
errmsg = e_invarg;
|
||||
}
|
||||
} else if (varp == &p_rtp) { // 'runtimepath'
|
||||
if (!nlua_update_package_path()) {
|
||||
errmsg = (char_u *)N_("E970: Failed to initialize lua interpreter");
|
||||
}
|
||||
} else {
|
||||
// Options that are a list of flags.
|
||||
p = NULL;
|
||||
|
74
test/functional/ex_cmds/packadd_spec.lua
Normal file
74
test/functional/ex_cmds/packadd_spec.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
|
||||
local clear = helpers.clear
|
||||
local eq = helpers.eq
|
||||
local exec_lua = helpers.exec_lua
|
||||
|
||||
describe('packadd', function()
|
||||
before_each(function()
|
||||
-- Primarily taken from test/functional/legacy/packadd_spec.lua
|
||||
clear()
|
||||
exec_lua [[
|
||||
TopDirectory = vim.fn.expand(vim.fn.getcwd() .. '/Xdir_lua')
|
||||
PlugDirectory = TopDirectory .. '/pack/mine/opt/mytest'
|
||||
|
||||
vim.o.packpath = TopDirectory
|
||||
|
||||
function FindPathsContainingDir(dir)
|
||||
return vim.fn.filter(
|
||||
vim.split(package.path, ';'),
|
||||
function(k, v)
|
||||
return string.find(v, 'mytest') ~= nil
|
||||
end
|
||||
)
|
||||
end
|
||||
]]
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
exec_lua [[
|
||||
vim.fn.delete(TopDirectory, 'rf')
|
||||
]]
|
||||
end)
|
||||
|
||||
it('should immediately update package.path in lua', function()
|
||||
local count_of_paths = exec_lua [[
|
||||
vim.fn.mkdir(PlugDirectory .. '/lua/', 'p')
|
||||
|
||||
local num_paths_before = #FindPathsContainingDir('mytest')
|
||||
|
||||
vim.cmd("packadd mytest")
|
||||
|
||||
local num_paths_after = #FindPathsContainingDir('mytest')
|
||||
|
||||
return { num_paths_before, num_paths_after }
|
||||
]]
|
||||
|
||||
eq({0, 2}, count_of_paths)
|
||||
end)
|
||||
|
||||
it('should immediately update package.path in lua even if lua directory does not exist', function()
|
||||
local count_of_paths = exec_lua [[
|
||||
vim.fn.mkdir(PlugDirectory .. '/plugin/', 'p')
|
||||
|
||||
local num_paths_before = #FindPathsContainingDir('mytest')
|
||||
|
||||
vim.cmd("packadd mytest")
|
||||
|
||||
local num_paths_after = #FindPathsContainingDir('mytest')
|
||||
|
||||
return { num_paths_before, num_paths_after }
|
||||
]]
|
||||
|
||||
eq({0, 2}, count_of_paths)
|
||||
end)
|
||||
|
||||
it('should error for invalid paths', function()
|
||||
local count_of_paths = exec_lua [[
|
||||
local ok, err = pcall(vim.cmd, "packadd asdf")
|
||||
return ok
|
||||
]]
|
||||
|
||||
eq(false, count_of_paths)
|
||||
end)
|
||||
end)
|
Reference in New Issue
Block a user