From a0ff79374848545adaa592e7f9d505ec942a3212 Mon Sep 17 00:00:00 2001 From: Dario48 Date: Mon, 13 Apr 2026 22:47:30 +0200 Subject: [PATCH] update plugin spec --- lua/plugins/blink-cmp.lua | 1 + lua/plugins/statusline.lua | 2 +- lua/utils/plugins.lua | 50 ++++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/lua/plugins/blink-cmp.lua b/lua/plugins/blink-cmp.lua index be1c8dc..90e9f02 100644 --- a/lua/plugins/blink-cmp.lua +++ b/lua/plugins/blink-cmp.lua @@ -55,4 +55,5 @@ return { vim.notify("Building blink.cmp failed", vim.log.levels.ERROR) end end, + } diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua index 1400f8e..0b761ea 100644 --- a/lua/plugins/statusline.lua +++ b/lua/plugins/statusline.lua @@ -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, } diff --git a/lua/utils/plugins.lua b/lua/utils/plugins.lua index 434eceb..faf6ce7 100644 --- a/lua/utils/plugins.lua +++ b/lua/utils/plugins.lua @@ -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) - 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 + for _, i in ipairs(plugin) do + M.load(i, opts) + end + 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 - 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)