Skip to content

Commit

Permalink
feat(commands): added highly experimental Lazy reload ... command. …
Browse files Browse the repository at this point in the history
…See #445
  • Loading branch information
folke committed May 27, 2023
1 parent d8a5829 commit a6c8f22
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lua/lazy/core/loader.lua
Expand Up @@ -227,10 +227,18 @@ function M.deactivate(plugin)
end

--- reload a plugin
---@param plugin LazyPlugin
---@param plugin LazyPlugin|string
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)
local load = false -- plugin._.loaded ~= nil

-- enable handlers
Handler.enable(plugin)
Expand Down
6 changes: 6 additions & 0 deletions lua/lazy/view/commands.lua
Expand Up @@ -53,6 +53,12 @@ M.commands = {
-- 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 })
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,
build = Manage.build,
clean = Manage.clean,
Expand Down
8 changes: 7 additions & 1 deletion lua/lazy/view/config.lua
Expand Up @@ -143,11 +143,17 @@ M.commands = {
},
build = {
desc = "Rebuild a plugin",
id = 13,
id = 15,
plugins = true,
plugins_required = true,
key_plugin = "gb",
},
reload = {
desc = "Reload a plugin (experimental!!)",
plugins = true,
plugins_required = true,
id = 16,
},
}

return M

0 comments on commit a6c8f22

Please sign in to comment.