From 24f6b6f1c7fb68f02335dd9579faee8b243e6a54 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 27 Sep 2023 12:39:39 +0200 Subject: [PATCH] fix: properly setup handlers when loading a plugin before startup (build) etc --- lua/lazy/core/handler/init.lua | 15 ++++++++++----- lua/lazy/core/loader.lua | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lua/lazy/core/handler/init.lua b/lua/lazy/core/handler/init.lua index af85820..9c6b92d 100644 --- a/lua/lazy/core/handler/init.lua +++ b/lua/lazy/core/handler/init.lua @@ -19,13 +19,19 @@ M.types = { ---@type table 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 @@ -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) diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index caf9087..1912338 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -34,6 +34,7 @@ function M.setup() -- load the plugins Plugin.load() + Handler.init() -- install missing plugins if Config.options.install.missing then @@ -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