perf: new file-based cache that ensures rtp is alweays correct and will cache all files, including those after startup

This commit is contained in:
Folke Lemaitre 2023-02-12 20:35:27 +01:00
parent 0d3f2c4042
commit e115f5ec17
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
8 changed files with 275 additions and 513 deletions

View file

@ -217,11 +217,44 @@ function M.walkmods(root, fn, modname)
end)
end
---@param modname string
function M.get_unloaded_rtp(modname)
modname = modname:gsub("/", ".")
local idx = modname:find(".", 1, true)
local topmod = idx and modname:sub(1, idx - 1) or modname
topmod = M.normname(topmod)
local rtp = {}
local Config = require("lazy.core.config")
if Config.spec then
for _, plugin in pairs(Config.spec.plugins) do
if not (plugin._.loaded or plugin.module == false) then
if topmod == M.normname(plugin.name) then
table.insert(rtp, 1, plugin.dir)
else
table.insert(rtp, plugin.dir)
end
end
end
end
return rtp
end
function M.find_root(modname)
local Cache = require("lazy.core.cache")
local rtp = vim.deepcopy(Cache.get_rtp())
vim.list_extend(rtp, M.get_unloaded_rtp(modname))
local modpath = Cache.find(modname, { rtp = rtp, patterns = { "", ".lua" } })
if modpath then
local root = modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
return root
end
end
---@param modname string
---@param fn fun(modname:string, modpath:string)
function M.lsmod(modname, fn)
local Cache = require("lazy.core.cache")
local root = Cache.find_root(modname)
local root = M.find_root(modname)
if not root then
return
end