diff --git a/lua/dep.lua b/lua/dep.lua index 79c0ed4..22842da 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -12,41 +12,44 @@ 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 + tree[1].get_root():reload() + if cb then cb() end end --- check if a package should be synced