mirror of https://github.com/folke/lazy.nvim.git
feat(plugin): support running all init functions
This commit is contained in:
parent
b1134ab82e
commit
9f4b3546f6
|
@ -111,9 +111,7 @@ function M.startup()
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
if plugin.init then
|
if plugin.init then
|
||||||
Util.track({ plugin = plugin.name, init = "init" })
|
Util.track({ plugin = plugin.name, init = "init" })
|
||||||
Util.try(function()
|
M.init(plugin)
|
||||||
plugin.init(plugin)
|
|
||||||
end, "Failed to run `init` for **" .. plugin.name .. "**")
|
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -157,6 +155,16 @@ function M.startup()
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param plugin LazyPlugin
|
||||||
|
function M.init(plugin)
|
||||||
|
Util.try(function()
|
||||||
|
local inits = Plugin.super_functions(plugin, "init")
|
||||||
|
for _, init in ipairs(inits) do
|
||||||
|
init(plugin)
|
||||||
|
end
|
||||||
|
end, "Failed to run `init` for **" .. plugin.name .. "**")
|
||||||
|
end
|
||||||
|
|
||||||
function M.get_start_plugins()
|
function M.get_start_plugins()
|
||||||
---@type LazyPlugin[]
|
---@type LazyPlugin[]
|
||||||
local start = {}
|
local start = {}
|
||||||
|
@ -264,9 +272,7 @@ function M.reload(plugin)
|
||||||
|
|
||||||
-- run init
|
-- run init
|
||||||
if plugin.init then
|
if plugin.init then
|
||||||
Util.try(function()
|
M.init(plugin)
|
||||||
plugin.init(plugin)
|
|
||||||
end, "Failed to run `init` for **" .. plugin.name .. "**")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if this is a start plugin, load it now
|
-- if this is a start plugin, load it now
|
||||||
|
|
|
@ -478,4 +478,22 @@ function M._values(root, plugin, prop, is_list)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Collects super values associated with a property that are functions
|
||||||
|
-- Used for init key
|
||||||
|
---@param plugin LazyPlugin
|
||||||
|
---@param prop string
|
||||||
|
---@return fun(self: LazyPlugin)[]
|
||||||
|
function M.super_functions(plugin, prop)
|
||||||
|
if not plugin[prop] then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
local super = getmetatable(plugin)
|
||||||
|
local result = super and M.super_functions(super.__index, prop) or {}
|
||||||
|
local value = rawget(plugin, prop)
|
||||||
|
if type(value) == "function" then
|
||||||
|
table.insert(result, value)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue