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

@ -72,7 +72,7 @@ function M.install_missing()
-- remove and installed plugins from indexed, so cache will index again
for _, p in pairs(Config.plugins) do
if p._.installed then
Cache.indexed[p.dir] = nil
Cache.reset(p.dir)
end
end
-- reload plugins
@ -341,7 +341,7 @@ function M.get_main(plugin)
local normname = Util.normname(plugin.name)
---@type string[]
local mods = {}
for _, modname in ipairs(Cache.get_topmods(plugin.dir)) do
for modname, _ in pairs(Cache.get_topmods(plugin.dir)) do
mods[#mods + 1] = modname
local modnorm = Util.normname(modname)
-- if we found an exact match, then use that
@ -450,4 +450,22 @@ function M.colorscheme(name)
end
end
---@param modname string
function M.loader(modname)
local modpath = Cache.find(modname, { rtp = Util.get_unloaded_rtp(modname) })
if modpath then
local plugin = Plugin.find(modpath)
if plugin and modpath:find(plugin.dir, 1, true) == 1 then
-- don't load if we're loading specs or if the plugin is already loaded
if not (Plugin.loading or plugin._.loaded) then
if plugin.module == false then
error("Plugin " .. plugin.name .. " is not loaded and is configured with module=false")
end
M.load(plugin, { require = modname })
end
return Cache._load(modname, modpath)
end
end
end
return M