mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
perf: new file-based cache that ensures correct rtp order (#532)
* perf: new file-based cache that ensures rtp is alweays correct and will cache all files, including those after startup * refactor: new cache * test: fix tests * fix(cache): cache file names on Windows * feat(cache): allow to disable the cache * docs: updated cache settings
This commit is contained in:
parent
06f835d0b4
commit
462633bae1
10 changed files with 354 additions and 549 deletions
|
@ -217,11 +217,46 @@ 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 modpath = Cache.find(modname, {
|
||||
rtp = true,
|
||||
paths = M.get_unloaded_rtp(modname),
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue