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) vim.notify("Building blink.cmp failed", vim.log.levels.ERROR)
end end
end, end,
} }

View file

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

View file

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