mirror of https://github.com/folke/lazy.nvim.git
feat(cache): use `vim.cache` everywhere. poly-fill when needed
This commit is contained in:
parent
4446d69c28
commit
ea1a044e3c
|
@ -183,7 +183,6 @@ function M.setup(opts)
|
||||||
if type(M.options.spec) == "string" then
|
if type(M.options.spec) == "string" then
|
||||||
M.options.spec = { import = M.options.spec }
|
M.options.spec = { import = M.options.spec }
|
||||||
end
|
end
|
||||||
M.options.performance.cache = require("lazy.core.cache").config
|
|
||||||
table.insert(M.options.install.colorscheme, "habamax")
|
table.insert(M.options.install.colorscheme, "habamax")
|
||||||
|
|
||||||
M.options.root = Util.norm(M.options.root)
|
M.options.root = Util.norm(M.options.root)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
local Handler = require("lazy.core.handler")
|
local Handler = require("lazy.core.handler")
|
||||||
local Cache = require("lazy.core.cache")
|
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
|
|
||||||
---@class LazyCoreLoader
|
---@class LazyCoreLoader
|
||||||
|
@ -73,7 +72,7 @@ function M.install_missing()
|
||||||
-- remove and installed plugins from indexed, so cache will index again
|
-- remove and installed plugins from indexed, so cache will index again
|
||||||
for _, p in pairs(Config.plugins) do
|
for _, p in pairs(Config.plugins) do
|
||||||
if p._.installed then
|
if p._.installed then
|
||||||
Cache.reset(p.dir)
|
vim.cache.reset(p.dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- reload plugins
|
-- reload plugins
|
||||||
|
@ -346,7 +345,7 @@ function M.get_main(plugin)
|
||||||
local normname = Util.normname(plugin.name)
|
local normname = Util.normname(plugin.name)
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local mods = {}
|
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
|
mods[#mods + 1] = modname
|
||||||
local modnorm = Util.normname(modname)
|
local modnorm = Util.normname(modname)
|
||||||
-- if we found an exact match, then use that
|
-- if we found an exact match, then use that
|
||||||
|
@ -476,7 +475,7 @@ end
|
||||||
---@param modname string
|
---@param modname string
|
||||||
function M.loader(modname)
|
function M.loader(modname)
|
||||||
local paths = Util.get_unloaded_rtp(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
|
if modpath then
|
||||||
M.auto_load(modname, modpath)
|
M.auto_load(modname, modpath)
|
||||||
local mod = package.loaded[modname]
|
local mod = package.loaded[modname]
|
||||||
|
@ -485,7 +484,7 @@ function M.loader(modname)
|
||||||
return mod
|
return mod
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Cache.load(modpath, { hash = hash })
|
return vim.cache.load(modpath, { hash = hash })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
local Handler = require("lazy.core.handler")
|
local Handler = require("lazy.core.handler")
|
||||||
local Cache = require("lazy.core.cache")
|
|
||||||
|
|
||||||
---@class LazyCorePlugin
|
---@class LazyCorePlugin
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -395,7 +394,6 @@ function M.load()
|
||||||
Util.track("state")
|
Util.track("state")
|
||||||
M.update_state()
|
M.update_state()
|
||||||
Util.track()
|
Util.track()
|
||||||
require("lazy.core.cache").indexed_unloaded = false
|
|
||||||
M.loading = false
|
M.loading = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -241,8 +241,7 @@ function M.get_unloaded_rtp(modname)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.find_root(modname)
|
function M.find_root(modname)
|
||||||
local Cache = require("lazy.core.cache")
|
local modpath = vim.cache.find(modname, {
|
||||||
local modpath = Cache.find(modname, {
|
|
||||||
rtp = true,
|
rtp = true,
|
||||||
paths = M.get_unloaded_rtp(modname),
|
paths = M.get_unloaded_rtp(modname),
|
||||||
patterns = { "", ".lua" },
|
patterns = { "", ".lua" },
|
||||||
|
|
|
@ -33,15 +33,20 @@ function M.setup(spec, opts)
|
||||||
end
|
end
|
||||||
local start = vim.loop.hrtime()
|
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 (
|
local enable_cache = not (
|
||||||
opts
|
opts
|
||||||
and opts.performance
|
and opts.performance
|
||||||
and opts.performance.cache
|
and opts.performance.cache
|
||||||
and opts.performance.cache.enabled == false
|
and opts.performance.cache.enabled == false
|
||||||
)
|
)
|
||||||
|
-- load module cache before anything else
|
||||||
if enable_cache then
|
if enable_cache then
|
||||||
require("lazy.core.cache").enable()
|
vim.cache.enable()
|
||||||
end
|
end
|
||||||
|
|
||||||
require("lazy.stats").track("LazyStart")
|
require("lazy.stats").track("LazyStart")
|
||||||
|
@ -53,7 +58,7 @@ function M.setup(spec, opts)
|
||||||
table.insert(package.loaders, 3, Loader.loader)
|
table.insert(package.loaders, 3, Loader.loader)
|
||||||
|
|
||||||
if vim.g.profile_loaders then
|
if vim.g.profile_loaders then
|
||||||
require("lazy.core.cache").profile_loaders()
|
vim.cache.profile_loaders()
|
||||||
end
|
end
|
||||||
|
|
||||||
Util.track({ plugin = "lazy.nvim" }) -- setup start
|
Util.track({ plugin = "lazy.nvim" }) -- setup start
|
||||||
|
|
|
@ -5,7 +5,6 @@ local Handler = require("lazy.core.handler")
|
||||||
local Git = require("lazy.manage.git")
|
local Git = require("lazy.manage.git")
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
local ViewConfig = require("lazy.view.config")
|
local ViewConfig = require("lazy.view.config")
|
||||||
local Cache = require("lazy.core.cache")
|
|
||||||
|
|
||||||
local Text = require("lazy.view.text")
|
local Text = require("lazy.view.text")
|
||||||
|
|
||||||
|
@ -676,7 +675,7 @@ function M:debug()
|
||||||
end)
|
end)
|
||||||
self:nl()
|
self:nl()
|
||||||
|
|
||||||
Util.foreach(Cache.stats, function(name, stats)
|
Util.foreach(vim.cache.stats, function(name, stats)
|
||||||
self:append(name, "LazyH2"):nl()
|
self:append(name, "LazyH2"):nl()
|
||||||
local props = {
|
local props = {
|
||||||
{ "total", stats.total or 0, "Number" },
|
{ "total", stats.total or 0, "Number" },
|
||||||
|
|
Loading…
Reference in New Issue