update plugin spec

This commit is contained in:
Dario48 2026-04-13 22:47:30 +02:00
commit a0ff793748
3 changed files with 31 additions and 22 deletions

View file

@ -55,4 +55,5 @@ return {
vim.notify("Building blink.cmp failed", vim.log.levels.ERROR)
end
end,
}

View file

@ -2,7 +2,7 @@
---@type Plugin
return {
configure = function(load)
load({ "Dario48/darioline", source = "https://dario48.site/git/" })
load("Dario48/darioline", { source = "https://dario48.site/git/" })
require("darioline").setup()
end,
}

View file

@ -4,39 +4,46 @@ M.loaded = {}
M.waiting = {}
---@alias pluginArray string|(pluginArray[])
---@class loadOpts
---@field source ?string
---@field packOpts ?vim.pack.keyset.add
---@alias loadFn fun(plugin: pluginArray, opts?: loadOpts): nil
---nice utility wrapper around vim.pack.add
---@param plugin string|table
function M.load(plugin)
---@type loadFn
function M.load(plugin, opts)
if plugin == nil then
error("value passed to load is nil")
end
if type(plugin) == "table" then
if type(plugin[1]) == "table" then
for _, i in ipairs(plugin) do
M.load(i)
M.load(i, opts)
end
elseif type(plugin[1]) == "string" then
local name = plugin[1]
if plugin.source == nil then
name = "https://github.com/" .. name
elseif type(plugin.source) == "string" then
name = plugin.source .. name
elseif type(plugin) == "string" then
if (opts == nil) then
vim.pack.add({ "https://github.com/" .. plugin })
else
if opts.source == nil then
plugin = "https://github.com/" .. plugin
elseif type(opts.source) == "string" then
plugin = opts.source .. plugin
else
error("plugin source must be either string or nil")
end
if plugin.load == nil then
vim.pack.add({ name })
if opts.packOpts == nil then
vim.pack.add({ plugin })
elseif type(opts.packOpts) == "table" then
vim.pack.add({ plugin }, opts.packOpts)
else
vim.pack.add({ name }, { load = plugin.load })
error("packOpts must be table")
end
end
else
error("table passed to load is invalid")
end
elseif type(plugin) == "string" then
vim.pack.add({ "https://github.com/" .. plugin })
else
error("value passed to load must be string or table [of tables]* of strings")
error("value passed to load must be string or table of tables or strings")
end
end
@ -62,7 +69,7 @@ local isDoneWaiting = function(pkg)
end
---@class Plugin
---@field configure fun(load: fun(string)): nil
---@field configure fun(load: loadFn): nil
---@field after? string|table
---@field configures? string
---@field onUpdate? fun(ev): nil
@ -95,6 +102,7 @@ function M.parse(plugin)
vim.api.nvim_create_autocmd("PackChanged", {
callback = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
print("name: ", name, ", kind: ", kind, ", configures: ", plugin.configures)
if name == plugin.configures and kind == "update" then
if not ev.data.active then
vim.cmd.packadd(plugin.configures)