feat(commands): added highly experimental `Lazy reload ...` command. See #445

This commit is contained in:
Folke Lemaitre 2023-05-27 15:19:50 +02:00
parent d8a5829fda
commit a6c8f22362
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 23 additions and 3 deletions

View File

@ -227,10 +227,18 @@ function M.deactivate(plugin)
end end
--- reload a plugin --- reload a plugin
---@param plugin LazyPlugin ---@param plugin LazyPlugin|string
function M.reload(plugin) function M.reload(plugin)
if type(plugin) == "string" then
plugin = Config.plugins[plugin]
end
if not plugin then
error("Plugin not found")
end
local load = plugin._.loaded ~= nil
M.deactivate(plugin) M.deactivate(plugin)
local load = false -- plugin._.loaded ~= nil
-- enable handlers -- enable handlers
Handler.enable(plugin) Handler.enable(plugin)

View File

@ -53,6 +53,12 @@ M.commands = {
-- when a command is executed with a bang, wait will be set -- when a command is executed with a bang, wait will be set
require("lazy.core.loader").load(opts.plugins, { cmd = "Lazy load" }, { force = opts.wait }) require("lazy.core.loader").load(opts.plugins, { cmd = "Lazy load" }, { force = opts.wait })
end, end,
reload = function(opts)
for _, plugin in pairs(opts.plugins) do
Util.warn("Reloading **" .. plugin.name .. "**")
require("lazy.core.loader").reload(plugin)
end
end,
log = Manage.log, log = Manage.log,
build = Manage.build, build = Manage.build,
clean = Manage.clean, clean = Manage.clean,

View File

@ -143,11 +143,17 @@ M.commands = {
}, },
build = { build = {
desc = "Rebuild a plugin", desc = "Rebuild a plugin",
id = 13, id = 15,
plugins = true, plugins = true,
plugins_required = true, plugins_required = true,
key_plugin = "gb", key_plugin = "gb",
}, },
reload = {
desc = "Reload a plugin (experimental!!)",
plugins = true,
plugins_required = true,
id = 16,
},
} }
return M return M