Skip to content

Commit

Permalink
feat(cache): use vim.cache everywhere. poly-fill when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Mar 14, 2023
1 parent 4446d69 commit ea1a044
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ function M.setup(opts)
if type(M.options.spec) == "string" then
M.options.spec = { import = M.options.spec }
end
M.options.performance.cache = require("lazy.core.cache").config
table.insert(M.options.install.colorscheme, "habamax")

M.options.root = Util.norm(M.options.root)
Expand Down
9 changes: 4 additions & 5 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local Util = require("lazy.core.util")
local Config = require("lazy.core.config")
local Handler = require("lazy.core.handler")
local Cache = require("lazy.core.cache")
local Plugin = require("lazy.core.plugin")

---@class LazyCoreLoader
Expand Down Expand Up @@ -73,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.reset(p.dir)
vim.cache.reset(p.dir)
end
end
-- reload plugins
Expand Down Expand Up @@ -346,7 +345,7 @@ function M.get_main(plugin)
local normname = Util.normname(plugin.name)
---@type string[]
local mods = {}
for modname, _ in pairs(Cache.lsmod(plugin.dir)) do
for modname, _ in pairs(vim.cache.lsmod(plugin.dir)) do
mods[#mods + 1] = modname
local modnorm = Util.normname(modname)
-- if we found an exact match, then use that
Expand Down Expand Up @@ -476,7 +475,7 @@ end
---@param modname string
function M.loader(modname)
local paths = Util.get_unloaded_rtp(modname)
local modpath, hash = Cache.find(modname, { rtp = false, paths = paths })
local modpath, hash = vim.cache.find(modname, { rtp = false, paths = paths })
if modpath then
M.auto_load(modname, modpath)
local mod = package.loaded[modname]
Expand All @@ -485,7 +484,7 @@ function M.loader(modname)
return mod
end
end
return Cache.load(modpath, { hash = hash })
return vim.cache.load(modpath, { hash = hash })
end
end

Expand Down
2 changes: 0 additions & 2 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local Config = require("lazy.core.config")
local Util = require("lazy.core.util")
local Handler = require("lazy.core.handler")
local Cache = require("lazy.core.cache")

---@class LazyCorePlugin
local M = {}
Expand Down Expand Up @@ -395,7 +394,6 @@ function M.load()
Util.track("state")
M.update_state()
Util.track()
require("lazy.core.cache").indexed_unloaded = false
M.loading = false
end

Expand Down
3 changes: 1 addition & 2 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ function M.get_unloaded_rtp(modname)
end

function M.find_root(modname)
local Cache = require("lazy.core.cache")
local modpath = Cache.find(modname, {
local modpath = vim.cache.find(modname, {
rtp = true,
paths = M.get_unloaded_rtp(modname),
patterns = { "", ".lua" },
Expand Down
11 changes: 8 additions & 3 deletions lua/lazy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ function M.setup(spec, opts)
end
local start = vim.loop.hrtime()

-- load module cache before anything else
-- poly-fill vim.cache
if not vim.cache then
vim.cache = require("lazy.core.cache")
end

local enable_cache = not (
opts
and opts.performance
and opts.performance.cache
and opts.performance.cache.enabled == false
)
-- load module cache before anything else
if enable_cache then
require("lazy.core.cache").enable()
vim.cache.enable()
end

require("lazy.stats").track("LazyStart")
Expand All @@ -53,7 +58,7 @@ function M.setup(spec, opts)
table.insert(package.loaders, 3, Loader.loader)

if vim.g.profile_loaders then
require("lazy.core.cache").profile_loaders()
vim.cache.profile_loaders()
end

Util.track({ plugin = "lazy.nvim" }) -- setup start
Expand Down
3 changes: 1 addition & 2 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local Handler = require("lazy.core.handler")
local Git = require("lazy.manage.git")
local Plugin = require("lazy.core.plugin")
local ViewConfig = require("lazy.view.config")
local Cache = require("lazy.core.cache")

local Text = require("lazy.view.text")

Expand Down Expand Up @@ -676,7 +675,7 @@ function M:debug()
end)
self:nl()

Util.foreach(Cache.stats, function(name, stats)
Util.foreach(vim.cache.stats, function(name, stats)
self:append(name, "LazyH2"):nl()
local props = {
{ "total", stats.total or 0, "Number" },
Expand Down

0 comments on commit ea1a044

Please sign in to comment.