configure packages after install

This commit is contained in:
Squibid 2026-01-01 17:26:14 -05:00
parent 09f1ae6854
commit e23bd277a6
Signed by: squibid
GPG key ID: BECE5684D3C4005D

View file

@ -12,41 +12,46 @@ local M = {}
---@param cb function? callback ---@param cb function? callback
local function synctree(tree, cb) local function synctree(tree, cb)
local progress = 0 local progress = 0
local has_errors = false
local function done(err) ---@param spec vim.pack.Spec
---@param path string
local function done(spec, path)
---@type package
local p = spec.data
_ = path
progress = progress + 1 progress = progress + 1
has_errors = has_errors or err
if progress == #tree then local info = vim.pack.get({ spec.name }, { info = false })[1]
if has_errors then if info.active then
logger:log("error", "there were errors during sync; see :messages or :DepLog for more information") p.exists = true
else p:unconfiguretree()
logger:log("update", "synchronized %s %s", #tree, #tree == 1 and "package" or "packages") p:runhooks("on_config")
end logger:log("config", "package: %s configured", p.id)
p.configured = true
for _, p in pairs(tree) do
p:reload()
end
if cb then
cb()
end
end end
end end
-- convert our spec to vim.pack.Spec -- convert our spec to vim.pack.Spec
---@type vim.pack.Spec[]
local vimspecs = {} local vimspecs = {}
for _, p in ipairs(tree) do for _, p in ipairs(tree) do
table.insert(vimspecs, { table.insert(vimspecs, {
name = p.name, name = p.name,
src = p.path or p.url, src = p.path or p.url,
version = p.commit or p.branch version = p.commit or p.branch,
data = p,
}) })
end end
-- install/update all packages
vim.pack.add(vimspecs, { load = done, confirm = false }) vim.pack.add(vimspecs, { load = done, confirm = false })
vim.pack.update(vimspecs, { force = true }) vim.pack.update(vimspecs, { force = true })
-- reload all packages
for _, p in pairs(vimspecs) do
p.data:reload()
end
if cb then cb() end
end end
--- check if a package should be synced --- check if a package should be synced