Skip to content

Commit

Permalink
fix: properly setup handlers when loading a plugin before startup (bu…
Browse files Browse the repository at this point in the history
…ild) etc
  • Loading branch information
folke committed Sep 27, 2023
1 parent 2a9354c commit 24f6b6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lua/lazy/core/handler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ M.types = {
---@type table<string,LazyHandler>
M.handlers = {}

function M.setup()
M.did_setup = false

function M.init()
for _, type in pairs(M.types) do
M.handlers[type] = M.new(type)
end
end

function M.setup()
M.did_setup = true
for _, plugin in pairs(Config.plugins) do
Util.try(function()
M.enable(plugin, true)
M.enable(plugin)
end, "Failed to setup handlers for " .. plugin.name)
end
end
Expand All @@ -40,9 +46,8 @@ function M.disable(plugin)
end

---@param plugin LazyPlugin
---@param force? boolean
function M.enable(plugin, force)
if force or not plugin._.loaded then
function M.enable(plugin)
if not plugin._.loaded then
for type, handler in pairs(M.handlers) do
if plugin[type] then
handler:add(plugin)
Expand Down
7 changes: 7 additions & 0 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function M.setup()

-- load the plugins
Plugin.load()
Handler.init()

-- install missing plugins
if Config.options.install.missing then
Expand Down Expand Up @@ -301,6 +302,12 @@ function M._load(plugin, reason, opts)
return
end

if not Handler.did_setup then
Util.try(function()
Handler.enable(plugin)
end, "Failed to setup handlers for " .. plugin.name)
end

---@diagnostic disable-next-line: assign-type-mismatch
plugin._.loaded = {}
for k, v in pairs(reason) do
Expand Down

0 comments on commit 24f6b6f

Please sign in to comment.