Skip to content

Commit

Permalink
fix(plugin): dont allow dir changes when we already loaded files fr…
Browse files Browse the repository at this point in the history
…om the plugin's old dir. Show an error in this case. Fixes #993
  • Loading branch information
folke committed Oct 15, 2023
1 parent 3dc413d commit c8e2091
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ end
function M.auto_load(modname, modpath)
local plugin = Plugin.find(modpath)
if plugin and modpath:find(plugin.dir, 1, true) == 1 then
plugin._.rtp_loaded = true
-- don't load if we're loading specs or if the plugin is already loaded
if not (Plugin.loading or plugin._.loaded) then
if plugin.module == false then
Expand Down
13 changes: 11 additions & 2 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,19 @@ function Spec:merge(old, new)
end

local new_dir = new._.dir or old._.dir or (new.name and (Config.options.root .. "/" .. new.name)) or nil
if new_dir ~= new.dir then
self:warn("Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. new.dir .. "`\n- to: `" .. new_dir .. "`")
if new_dir ~= old.dir then
local msg = "Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. old.dir .. "`\n- to: `" .. new_dir .. "`"
if new._.rtp_loaded or old._.rtp_loaded then
msg = msg
.. "\n\nThis plugin was already partially loaded, so we did not change it's `dir`.\nPlease fix your config."
self:error(msg)
new_dir = old.dir
else
self:warn(msg)
end
end
new.dir = new_dir
new._.rtp_loaded = new._.rtp_loaded or old._.rtp_loaded

new._.super = old
setmetatable(new, { __index = old })
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
---@field super? LazyPlugin
---@field module? string
---@field dir? string Explicit dir or dev set for this plugin
---@field rtp_loaded? boolean

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

Expand Down

0 comments on commit c8e2091

Please sign in to comment.