From 21a219a825cd9d9b049471ccd7831d117d7cede3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 15 Mar 2023 09:01:00 +0100 Subject: [PATCH] refactor(cache): revert all `vim.cache` changes and disable it if it would ever exist --- lua/lazy/core/cache.lua | 10 ---------- lua/lazy/core/loader.lua | 9 +++++---- lua/lazy/core/util.lua | 2 +- lua/lazy/init.lua | 12 +++++++----- lua/lazy/view/render.lua | 2 +- scripts/update-neovim-cache | 4 ---- 6 files changed, 14 insertions(+), 25 deletions(-) delete mode 100755 scripts/update-neovim-cache diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index fac7262..7a4c0d7 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -1,13 +1,3 @@ ----@diagnostic disable: duplicate-doc-alias ----@diagnostic disable: duplicate-doc-field ----@diagnostic disable: duplicate-set-field - --- interop with the native Neovim cache -if type(package.loaded["vim.cache"]) == "table" then - return package.loaded["vim.cache"] -end - --- NEOVIM local uv = vim.loop local M = {} diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 1d4e745..85954f6 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -2,6 +2,7 @@ local Util = require("lazy.core.util") local Config = require("lazy.core.config") local Handler = require("lazy.core.handler") local Plugin = require("lazy.core.plugin") +local Cache = require("lazy.core.cache") ---@class LazyCoreLoader local M = {} @@ -72,7 +73,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 - vim.cache.reset(p.dir) + Cache.reset(p.dir) end end -- reload plugins @@ -345,7 +346,7 @@ function M.get_main(plugin) local normname = Util.normname(plugin.name) ---@type string[] local mods = {} - for modname, _ in pairs(vim.cache.lsmod(plugin.dir)) do + for modname, _ in pairs(Cache.lsmod(plugin.dir)) do mods[#mods + 1] = modname local modnorm = Util.normname(modname) -- if we found an exact match, then use that @@ -475,7 +476,7 @@ end ---@param modname string function M.loader(modname) local paths = Util.get_unloaded_rtp(modname) - local modpath, hash = vim.cache.find(modname, { rtp = false, paths = paths }) + local modpath, hash = Cache.find(modname, { rtp = false, paths = paths }) if modpath then M.auto_load(modname, modpath) local mod = package.loaded[modname] @@ -484,7 +485,7 @@ function M.loader(modname) return mod end end - return vim.cache.load(modpath, { hash = hash }) + return Cache.load(modpath, { hash = hash }) end end diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index 0450cb0..10c5c0a 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -241,7 +241,7 @@ function M.get_unloaded_rtp(modname) end function M.find_root(modname) - local modpath = vim.cache.find(modname, { + local modpath = require("lazy.core.cache").find(modname, { rtp = true, paths = M.get_unloaded_rtp(modname), patterns = { "", ".lua" }, diff --git a/lua/lazy/init.lua b/lua/lazy/init.lua index 9b29adb..14a8de5 100644 --- a/lua/lazy/init.lua +++ b/lua/lazy/init.lua @@ -33,11 +33,13 @@ function M.setup(spec, opts) end local start = vim.loop.hrtime() - -- poly-fill vim.cache - if not vim.cache then - vim.cache = require("lazy.core.cache") + -- disable the Neovim cache if it would ever be added + if vim.cache and vim.cache.disable then + vim.cache.disable() end + local Cache = require("lazy.core.cache") + local enable_cache = not ( opts and opts.performance @@ -46,7 +48,7 @@ function M.setup(spec, opts) ) -- load module cache before anything else if enable_cache then - vim.cache.enable() + Cache.enable() end require("lazy.stats").track("LazyStart") @@ -58,7 +60,7 @@ function M.setup(spec, opts) table.insert(package.loaders, 3, Loader.loader) if vim.g.profile_loaders then - vim.cache.profile_loaders() + Cache.profile_loaders() end Util.track({ plugin = "lazy.nvim" }) -- setup start diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index 9735bb9..0a1cd80 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -675,7 +675,7 @@ function M:debug() end) self:nl() - Util.foreach(vim.cache.stats, function(name, stats) + Util.foreach(require("lazy.core.cache").stats, function(name, stats) self:append(name, "LazyH2"):nl() local props = { { "total", stats.total or 0, "Number" }, diff --git a/scripts/update-neovim-cache b/scripts/update-neovim-cache deleted file mode 100755 index 89b5665..0000000 --- a/scripts/update-neovim-cache +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/env bash -cd ~/projects/neovim || exit -sed -n '/NEOVIM/,$p' ~/projects/lazy.nvim/lua/lazy/core/cache.lua | sed '1d' | rg -v "selene" >./runtime/lua/vim/cache.lua -stylua ./runtime/lua/vim/cache.lua