Skip to content

Commit c8e2091

Browse files
committed
fix(plugin): dont allow dir changes when we already loaded files from the plugin's old dir. Show an error in this case. Fixes #993
1 parent 3dc413d commit c8e2091

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lua/lazy/core/loader.lua

+1
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ end
495495
function M.auto_load(modname, modpath)
496496
local plugin = Plugin.find(modpath)
497497
if plugin and modpath:find(plugin.dir, 1, true) == 1 then
498+
plugin._.rtp_loaded = true
498499
-- don't load if we're loading specs or if the plugin is already loaded
499500
if not (Plugin.loading or plugin._.loaded) then
500501
if plugin.module == false then

lua/lazy/core/plugin.lua

+11-2
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,19 @@ function Spec:merge(old, new)
459459
end
460460

461461
local new_dir = new._.dir or old._.dir or (new.name and (Config.options.root .. "/" .. new.name)) or nil
462-
if new_dir ~= new.dir then
463-
self:warn("Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. new.dir .. "`\n- to: `" .. new_dir .. "`")
462+
if new_dir ~= old.dir then
463+
local msg = "Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. old.dir .. "`\n- to: `" .. new_dir .. "`"
464+
if new._.rtp_loaded or old._.rtp_loaded then
465+
msg = msg
466+
.. "\n\nThis plugin was already partially loaded, so we did not change it's `dir`.\nPlease fix your config."
467+
self:error(msg)
468+
new_dir = old.dir
469+
else
470+
self:warn(msg)
471+
end
464472
end
465473
new.dir = new_dir
474+
new._.rtp_loaded = new._.rtp_loaded or old._.rtp_loaded
466475

467476
new._.super = old
468477
setmetatable(new, { __index = old })

lua/lazy/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
---@field super? LazyPlugin
2020
---@field module? string
2121
---@field dir? string Explicit dir or dev set for this plugin
22+
---@field rtp_loaded? boolean
2223

2324
---@alias PluginOpts table|fun(self:LazyPlugin, opts:table):table?
2425

0 commit comments

Comments
 (0)