feat: add PluginSpec.config

This commit is contained in:
Marc Jakobi
2024-06-10 11:10:36 +02:00
parent f89778db34
commit b52a46c624
3 changed files with 19 additions and 23 deletions
+2 -2
View File
@@ -8,10 +8,10 @@ end
---@param spec string | lz.n.Spec
function M.load(spec)
if vim.g.lzn_did_load then
if vim.g.lz_n_did_load then
return vim.notify("lz.n has already loaded your plugins.", vim.log.levels.WARN, { title = "lz.n" })
end
vim.g.lzn_did_load = true
vim.g.lz_n_did_load = true
if type(spec) == "string" then
spec = { import = spec }
+16
View File
@@ -67,6 +67,21 @@ function M.load_startup_plugins(plugins)
end
end
---@param plugin lz.n.Plugin
local function config(plugin)
if type(plugin.config) == "function" then
xpcall(
plugin.config,
vim.schedule_wrap(function(err)
vim.notify(
"Failed to run 'config' for " .. plugin.name .. ": " .. tostring(err or ""),
vim.log.levels.ERROR
)
end)
)
end
end
---@param plugins string | lz.n.Plugin | string[] | lz.n.Plugin[]
function M.load(plugins)
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
@@ -84,6 +99,7 @@ function M.load(plugins)
end
if loadable then
M._load(plugin)
config(plugin)
end
end
end
+1 -21
View File
@@ -1,31 +1,10 @@
---@meta
error("Cannot import a meta module")
--- TODO Implement before/after config API
--- @class VimGTable vim.g config table
---
--- Name of the vim.g config table, e.g. "rustaceanvim" for "vim.g.rustaceanvim".
--- Defaults to the plugin name.
--- @field name? string
--- @field type 'vim.g'
--- @class ConfigFunction Lua function
---
--- Module name containing the function. Defaults to the plugin name.
--- @field module? string
--- Name of the config function.
--- Defaults to 'setup', the most common in the Neovim plugin community.
--- @field name? string
--- @field type 'func'
--- @alias lz.n.PluginOptsSpec VimGTable | ConfigFunction How a plugin accepts its options
--- @class lz.n.PluginBase
---
--- The plugin name (not its main module), e.g. "sweetie.nvim"
--- @field name string
--- @field optsSpec? lz.n.PluginOptsSpec
---
--- Whether to enable this plugin. Useful to disable plugins under certain conditions.
--- @field enabled? boolean|(fun():boolean)
@@ -43,6 +22,7 @@ error("Cannot import a meta module")
--- @field beforeAll? fun(self:lz.n.Plugin) Will be run before loading any plugins
--- @field after? fun(self:lz.n.Plugin, opts:table)|true Will be executed when loading the plugin
--- @field opts? table
--- @field config? fun() Will be executed when loading the plugin
--- @package
--- @class lz.n.PluginHandlers