configure packages after install
This commit is contained in:
parent
09f1ae6854
commit
e23bd277a6
1 changed files with 23 additions and 18 deletions
41
lua/dep.lua
41
lua/dep.lua
|
|
@ -12,41 +12,46 @@ local M = {}
|
|||
---@param cb function? callback
|
||||
local function synctree(tree, cb)
|
||||
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
|
||||
has_errors = has_errors or err
|
||||
|
||||
if progress == #tree then
|
||||
if has_errors then
|
||||
logger:log("error", "there were errors during sync; see :messages or :DepLog for more information")
|
||||
else
|
||||
logger:log("update", "synchronized %s %s", #tree, #tree == 1 and "package" or "packages")
|
||||
end
|
||||
|
||||
for _, p in pairs(tree) do
|
||||
p:reload()
|
||||
end
|
||||
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
local info = vim.pack.get({ spec.name }, { info = false })[1]
|
||||
if info.active then
|
||||
p.exists = true
|
||||
p:unconfiguretree()
|
||||
p:runhooks("on_config")
|
||||
logger:log("config", "package: %s configured", p.id)
|
||||
p.configured = true
|
||||
end
|
||||
end
|
||||
|
||||
-- convert our spec to vim.pack.Spec
|
||||
---@type vim.pack.Spec[]
|
||||
local vimspecs = {}
|
||||
for _, p in ipairs(tree) do
|
||||
table.insert(vimspecs, {
|
||||
name = p.name,
|
||||
src = p.path or p.url,
|
||||
version = p.commit or p.branch
|
||||
version = p.commit or p.branch,
|
||||
data = p,
|
||||
})
|
||||
end
|
||||
|
||||
-- install/update all packages
|
||||
vim.pack.add(vimspecs, { load = done, confirm = false })
|
||||
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
|
||||
|
||||
--- check if a package should be synced
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue