mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-01 18:35:18 +00:00
feat(trigger_load): return list of skipped plugins instead of failing (#70)
This commit is contained in:
+2
-2
@@ -27,9 +27,9 @@ end
|
||||
--- Once a plugin has been loaded, it will be removed from all handlers (via `del`).
|
||||
--- As a result, calling `trigger_load` with a plugin name is stateful and idempotent.
|
||||
---@overload fun(plugins: lz.n.Plugin | string[] | lz.n.Plugin[] | table<unknown, lz.n.Plugin>)
|
||||
---@overload fun(plugins: string | string[], opts: lz.n.lookup.Opts)
|
||||
---@overload fun(plugins: string | string[], opts: lz.n.lookup.Opts): string[]
|
||||
M.trigger_load = function(plugins, opts)
|
||||
require("lz.n.loader").load(plugins, function(name)
|
||||
return require("lz.n.loader").load(plugins, function(name)
|
||||
return M.lookup(name, opts)
|
||||
end)
|
||||
end
|
||||
|
||||
+13
-6
@@ -99,26 +99,33 @@ local function hook(hook_key, plugin)
|
||||
end
|
||||
|
||||
---@overload fun(plugins: lz.n.Plugin | string[] | lz.n.Plugin[] | table<unknown, lz.n.Plugin>)
|
||||
---@overload fun(plugins: string | string[], lookup: fun(name: string): lz.n.Plugin?)
|
||||
---@overload fun(plugins: string | string[], lookup: fun(name: string): lz.n.Plugin?): string[]
|
||||
function M.load(plugins, lookup)
|
||||
local iterator = vim.islist(plugins) and ipairs or pairs
|
||||
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
|
||||
---@cast plugins (string|lz.n.Plugin)[] | table<unknown, lz.n.Plugin>
|
||||
---@type string[]
|
||||
local skipped = {}
|
||||
for _, plugin in iterator(plugins) do
|
||||
local loadable = true
|
||||
-- NOTE: do not make this loop into vim.iter
|
||||
-- https://github.com/nvim-neorocks/lz.n/pull/21
|
||||
if type(plugin) == "string" then
|
||||
---@diagnostic disable-next-line: cast-local-type
|
||||
plugin = lookup and lookup(plugin) or plugin
|
||||
if type(plugin) == "string" then
|
||||
vim.notify("Plugin " .. plugin .. " not found", vim.log.levels.ERROR, { title = "lz.n" })
|
||||
return
|
||||
loadable = false
|
||||
table.insert(skipped, plugin)
|
||||
end
|
||||
---@cast plugin lz.n.Plugin
|
||||
end
|
||||
hook("before", plugin)
|
||||
M._load(plugin)
|
||||
hook("after", plugin)
|
||||
if loadable then
|
||||
hook("before", plugin)
|
||||
M._load(plugin)
|
||||
hook("after", plugin)
|
||||
end
|
||||
end
|
||||
return skipped
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user