fix(cache): keep ordering of topmods the same as in rtp

This commit is contained in:
Folke Lemaitre 2023-01-01 18:52:07 +01:00
parent b23a5dc8d5
commit 11eee43c7e
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 6 additions and 4 deletions

View File

@ -37,8 +37,8 @@ M.stats = {
} }
M.me = debug.getinfo(1, "S").source:sub(2) M.me = debug.getinfo(1, "S").source:sub(2)
M.me = vim.fn.fnamemodify(M.me, ":p:h:h:h:h"):gsub("\\", "/") M.me = vim.fn.fnamemodify(M.me, ":p:h:h:h:h"):gsub("\\", "/")
---@type table<string, table<string,string>> ---@type table<string, string[]>
M.topmods = { lazy = { [M.me] = M.me } } M.topmods = { lazy = { M.me } }
---@type table<string, string[]> ---@type table<string, string[]>
M.indexed = { [M.me] = { "lazy" } } M.indexed = { [M.me] = { "lazy" } }
M.indexed_unloaded = false M.indexed_unloaded = false
@ -229,7 +229,9 @@ function M._index(path)
end end
if topname then if topname then
M.topmods[topname] = M.topmods[topname] or {} M.topmods[topname] = M.topmods[topname] or {}
M.topmods[topname][path] = path if not vim.tbl_contains(M.topmods[topname], path) then
table.insert(M.topmods[topname], path)
end
table.insert(M.indexed[path], topname) table.insert(M.indexed[path], topname)
end end
end) end)
@ -257,7 +259,7 @@ function M.find(modname)
-- check top-level mods to find the module -- check top-level mods to find the module
local function _find() local function _find()
for _, toppath in pairs(M.topmods[topmod] or {}) do for _, toppath in ipairs(M.topmods[topmod] or {}) do
for _, pattern in ipairs(patterns) do for _, pattern in ipairs(patterns) do
local path = toppath .. "/lua/" .. basename .. pattern local path = toppath .. "/lua/" .. basename .. pattern
M.stats.find.stat = M.stats.find.stat + 1 M.stats.find.stat = M.stats.find.stat + 1