mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
feat(spec): event, keys, ft and cmd can now also be a function that returns the values to be used
This commit is contained in:
parent
bcd87a0215
commit
2128ca90fb
6 changed files with 76 additions and 75 deletions
|
@ -231,33 +231,14 @@ function M._load(plugin, reason, opts)
|
|||
end)
|
||||
end
|
||||
|
||||
-- Merges super opts or runs the opts function to override opts or return new ones
|
||||
---@param plugin LazyPlugin
|
||||
function M.opts(plugin)
|
||||
---@type table
|
||||
local opts = plugin._.super and M.opts(plugin._.super) or {}
|
||||
---@type PluginOpts?
|
||||
local plugin_opts = rawget(plugin, "opts")
|
||||
|
||||
if type(plugin_opts) == "table" then
|
||||
opts = Util.merge(opts, plugin_opts)
|
||||
elseif type(plugin_opts) == "function" then
|
||||
local new_opts = plugin_opts(plugin, opts)
|
||||
if new_opts then
|
||||
opts = new_opts
|
||||
end
|
||||
end
|
||||
|
||||
return opts
|
||||
end
|
||||
|
||||
--- runs plugin config
|
||||
---@param plugin LazyPlugin
|
||||
function M.config(plugin)
|
||||
local opts = Plugin.values(plugin, "opts", false)
|
||||
local fn
|
||||
if type(plugin.config) == "function" then
|
||||
fn = function()
|
||||
plugin.config(plugin, M.opts(plugin))
|
||||
plugin.config(plugin, opts)
|
||||
end
|
||||
else
|
||||
local normname = Util.normname(plugin.name)
|
||||
|
@ -274,7 +255,7 @@ function M.config(plugin)
|
|||
end
|
||||
if #mods == 1 then
|
||||
fn = function()
|
||||
require(mods[1]).setup(M.opts(plugin))
|
||||
require(mods[1]).setup(opts)
|
||||
end
|
||||
else
|
||||
return Util.error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue