fix(pkg): correctly pre-load package specs and remove them when needed during resolve

This commit is contained in:
Folke Lemaitre 2024-06-23 17:49:19 +02:00
parent ee2ca39f67
commit 4326d4b487
6 changed files with 87 additions and 38 deletions

View file

@ -7,6 +7,7 @@ local M = {}
---@class LazyPkg
---@field source string
---@field name string
---@field file string
---@field spec? LazySpec
---@field chunk? string|fun():LazySpec
@ -30,6 +31,7 @@ function M.update()
for _, source in ipairs(sources) do
local spec = source.get(plugin)
if spec then
spec.name = plugin.name
if type(spec.chunk) == "function" then
spec.chunk = string.dump(spec.chunk)
end
@ -81,6 +83,25 @@ function M.get(plugin)
return ret
end
function M.spec()
if not M.cache then
_load()
end
---@type table<string,LazyPluginSpec>
local ret = {}
for dir in pairs(M.cache) do
local pkg = M.get({ dir = dir })
local spec = pkg and pkg.spec
if pkg and spec then
spec = type(spec) == "table" and vim.deepcopy(spec) or spec
ret[dir] = { pkg.name, specs = spec }
end
end
return ret
end
---@param plugin LazyPlugin
---@return LazySpec?
function M.get_spec(plugin)