feat: `Plugin.specs()` can now reload and keeps existing state

This commit is contained in:
Folke Lemaitre 2022-12-02 17:02:25 +01:00
parent ebf15fc198
commit 330dbe7203
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 8 additions and 0 deletions

View File

@ -188,6 +188,7 @@ function M.spec()
-- spec is a module -- spec is a module
local function _load(name) local function _load(name)
local modname = name and (Config.spec .. "." .. name) or Config.spec local modname = name and (Config.spec .. "." .. name) or Config.spec
package.loaded[modname] = nil
Util.try(function() Util.try(function()
spec:normalize(require(modname)) spec:normalize(require(modname))
end, "Failed to load **" .. modname .. "**") end, "Failed to load **" .. modname .. "**")
@ -212,7 +213,14 @@ function M.load()
spec.plugins["lazy.nvim"] = nil spec.plugins["lazy.nvim"] = nil
spec:add({ "folke/lazy.nvim", lazy = true }) spec:add({ "folke/lazy.nvim", lazy = true })
local existing = Config.plugins
Config.plugins = spec.plugins Config.plugins = spec.plugins
-- copy state. This wont do anything during startup
for name, plugin in pairs(existing) do
if Config.plugins[name] then
Config.plugins[name]._ = plugin._
end
end
Util.track() Util.track()
Util.track("state") Util.track("state")