mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-20 05:16:45 +00:00
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:
parent
0d3f2c4042
commit
e115f5ec17
8 changed files with 275 additions and 513 deletions
|
@ -52,9 +52,9 @@ describe("util", function()
|
|||
|
||||
-- test with empty cache
|
||||
Cache.cache = {}
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
local root = Cache.find_root(test.mod)
|
||||
Cache._topmods = {}
|
||||
Cache.topmods_rtp = false
|
||||
local root = Util.find_root(test.mod)
|
||||
assert(root, "no root found for " .. test.mod .. " (test " .. t .. ")")
|
||||
assert.same(Helpers.path(test.root), root)
|
||||
local mods = {}
|
||||
|
@ -69,9 +69,9 @@ describe("util", function()
|
|||
for i, file in ipairs(files) do
|
||||
Cache.cache[test.mods[i]] = { modpath = file }
|
||||
end
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
root = Cache.find_root(test.mod)
|
||||
Cache._topmods = {}
|
||||
Cache.topmods_rtp = false
|
||||
root = Util.find_root(test.mod)
|
||||
assert(root, "no root found for " .. test.mod .. " (test " .. t .. ")")
|
||||
assert.same(Helpers.path(test.root), root)
|
||||
mods = {}
|
||||
|
@ -85,12 +85,12 @@ describe("util", function()
|
|||
|
||||
it("find the correct root with dels", function()
|
||||
Cache.cache = {}
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
Cache._topmods = {}
|
||||
Cache.topmods_rtp = false
|
||||
vim.opt.rtp:append(Helpers.path("old"))
|
||||
Helpers.fs_create({ "old/lua/foobar/init.lua" })
|
||||
Cache.cache["foobar"] = { modpath = Helpers.path("old/lua/foobar/init.lua") }
|
||||
local root = Cache.find_root("foobar")
|
||||
local root = Util.find_root("foobar")
|
||||
assert(root, "foobar root not found")
|
||||
assert.same(Helpers.path("old/lua/foobar"), root)
|
||||
|
||||
|
@ -98,24 +98,22 @@ describe("util", function()
|
|||
assert(not vim.loop.fs_stat(Helpers.path("old/lua/foobar")), "old/lua/foobar should not exist")
|
||||
|
||||
-- vim.opt.rtp = rtp
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
Cache._topmods = {}
|
||||
vim.opt.rtp:append(Helpers.path("new"))
|
||||
Helpers.fs_create({ "new/lua/foobar/init.lua" })
|
||||
root = Cache.find_root("foobar")
|
||||
root = Util.find_root("foobar")
|
||||
assert(root, "foobar root not found")
|
||||
assert.same(Helpers.path("new/lua/foobar"), root)
|
||||
end)
|
||||
|
||||
it("find the correct root with mod dels", function()
|
||||
Cache.cache = {}
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
Cache._topmods = {}
|
||||
Cache.enabled = true
|
||||
vim.opt.rtp:append(Helpers.path("old"))
|
||||
Helpers.fs_create({ "old/lua/foobar/test.lua" })
|
||||
Cache.cache["foobar.test"] = { modpath = Helpers.path("old/lua/foobar/test.lua") }
|
||||
local root = Cache.find_root("foobar")
|
||||
local root = Util.find_root("foobar")
|
||||
assert(root, "foobar root not found")
|
||||
assert.same(Helpers.path("old/lua/foobar"), root)
|
||||
assert(not Cache.cache["foobar"], "foobar should not be in cache")
|
||||
|
@ -124,11 +122,10 @@ describe("util", function()
|
|||
Helpers.fs_rm("old")
|
||||
|
||||
-- vim.opt.rtp = rtp
|
||||
Cache.indexed = {}
|
||||
Cache.indexed_rtp = false
|
||||
Cache._topmods = {}
|
||||
vim.opt.rtp:append(Helpers.path("new"))
|
||||
Helpers.fs_create({ "new/lua/foobar/test.lua" })
|
||||
root = Cache.find_root("foobar")
|
||||
root = Util.find_root("foobar")
|
||||
assert(root, "foobar root not found")
|
||||
assert.same(Helpers.path("new/lua/foobar"), root)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue