fix(loader): don't load handlers before installing plugins

This commit is contained in:
Folke Lemaitre 2023-10-16 15:05:16 +02:00
parent ed6c9ffe21
commit 1cfd6d1f36
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
6 changed files with 49 additions and 25 deletions

View File

@ -64,10 +64,11 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M:values(plugin) function M:values(plugin)
local Plugin = require("lazy.core.plugin")
---@type table<string,any> ---@type table<string,any>
local values = {} local values = {}
---@diagnostic disable-next-line: no-unknown ---@diagnostic disable-next-line: no-unknown
for _, value in ipairs(plugin[self.type] or {}) do for _, value in ipairs(Plugin.values(plugin, self.type, true)) do
local event = self:parse(value) local event = self:parse(value)
values[event.id] = event values[event.id] = event
end end

View File

@ -39,6 +39,10 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M.disable(plugin) function M.disable(plugin)
if not plugin._.handlers_enabled then
return
end
plugin._.handlers_enabled = false
for type, handler in pairs(M.handlers) do for type, handler in pairs(M.handlers) do
if plugin[type] then if plugin[type] then
handler:del(plugin) handler:del(plugin)
@ -49,11 +53,15 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M.enable(plugin) function M.enable(plugin)
if not plugin._.loaded then if not plugin._.loaded then
if plugin._.handlers_enabled then
return
end
for type, handler in pairs(M.handlers) do for type, handler in pairs(M.handlers) do
if plugin[type] then if plugin[type] then
handler:add(plugin) handler:add(plugin)
end end
end end
plugin._.handlers_enabled = true
end end
end end
@ -80,10 +88,11 @@ function M:_del(_value) end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M:values(plugin) function M:values(plugin)
local Plugin = require("lazy.core.plugin")
---@type table<string,any> ---@type table<string,any>
local values = {} local values = {}
---@diagnostic disable-next-line: no-unknown ---@diagnostic disable-next-line: no-unknown
for _, value in ipairs(plugin[self.type] or {}) do for _, value in ipairs(Plugin.values(plugin, self.type, true)) do
values[value] = value values[value] = value
end end
return values return values

View File

@ -52,7 +52,8 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M:values(plugin) function M:values(plugin)
return M.resolve(plugin.keys) local Plugin = require("lazy.core.plugin")
return M.resolve(Plugin.values(plugin, "keys", true))
end end
---@param spec? (string|LazyKeysSpec)[] ---@param spec? (string|LazyKeysSpec)[]

View File

@ -42,15 +42,6 @@ end
function Spec:parse(spec) function Spec:parse(spec)
self:normalize(spec) self:normalize(spec)
self:fix_disabled() self:fix_disabled()
-- calculate handlers
for _, plugin in pairs(self.plugins) do
for _, handler in pairs(Handler.types) do
if plugin[handler] then
plugin[handler] = M.values(plugin, handler, true)
end
end
end
end end
-- PERF: optimized code to get package name without using lua patterns -- PERF: optimized code to get package name without using lua patterns
@ -609,8 +600,26 @@ end
---@param prop string ---@param prop string
---@param is_list? boolean ---@param is_list? boolean
function M.values(plugin, prop, is_list) function M.values(plugin, prop, is_list)
if not plugin[prop] then
return {}
end
plugin._.values = plugin._.values or {}
local key = prop .. (is_list and "_list" or "")
if plugin._.values[key] == nil then
plugin[prop] = M._values(plugin, prop, is_list)
plugin._.values[key] = true
end
return plugin[prop] or {}
end
-- Merges super values or runs the values function to override values or return new ones
-- Used for opts, cmd, event, ft and keys
---@param plugin LazyPlugin
---@param prop string
---@param is_list? boolean
function M._values(plugin, prop, is_list)
---@type table ---@type table
local ret = plugin._.super and M.values(plugin._.super, prop, is_list) or {} local ret = plugin._.super and M._values(plugin._.super, prop, is_list) or {}
local values = rawget(plugin, prop) local values = rawget(plugin, prop)
if not values then if not values then

View File

@ -20,6 +20,8 @@
---@field module? string ---@field module? string
---@field dir? string Explicit dir or dev set for this plugin ---@field dir? string Explicit dir or dev set for this plugin
---@field rtp_loaded? boolean ---@field rtp_loaded? boolean
---@field values? table<string,boolean>
---@field handlers_enabled? boolean
---@alias PluginOpts table|fun(self:LazyPlugin, opts:table):table? ---@alias PluginOpts table|fun(self:LazyPlugin, opts:table):table?

View File

@ -415,7 +415,7 @@ function M:plugin(plugin)
else else
self:append(" ") self:append(" ")
local reason = {} local reason = {}
if plugin._.kind ~= "disabled" then if plugin._.kind ~= "disabled" and plugin._.handlers_enabled then
for handler in pairs(Handler.types) do for handler in pairs(Handler.types) do
if plugin[handler] then if plugin[handler] then
local values = Handler.handlers[handler]:values(plugin) local values = Handler.handlers[handler]:values(plugin)
@ -542,17 +542,19 @@ function M:details(plugin)
end end
end) end)
for handler in pairs(Handler.types) do if plugin._.handlers_enabled then
if plugin[handler] then for handler in pairs(Handler.types) do
table.insert(props, { if plugin[handler] then
handler, table.insert(props, {
function() handler,
for _, value in ipairs(plugin[handler]) do function()
self:reason({ [handler] = value }) for _, value in ipairs(Plugin.values(plugin, handler, true)) do
self:append(" ") self:reason({ [handler] = value })
end self:append(" ")
end, end
}) end,
})
end
end end
end end
self:props(props, { indent = 6 }) self:props(props, { indent = 6 })