diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index 3a8aa05..12d9394 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -9,13 +9,12 @@ M.dirty = false M.config = { enabled = true, path = vim.fn.stdpath("state") .. "/lazy.state", - -- choose what should be cached - -- * lazy: cache all lazy.nvim core modules and your config files - -- * init: all of the above and any module needed to init your plugins - -- * VimEnter: any module till VimEnter - -- * VeryLazy: any module till VeryLazy - -- * allthethings: all mdules. Not recommended - strategy = "VimEnter", ---@type "lazy"|"init"|"VimEnter"|"allthethings" + -- Once one of the following events triggers, caching will be disabled. + -- To cache all modules, set this to `{}`, but that is not recommended. + -- The default is to disable on: + -- * VimEnter: not useful to cache anything else beyond startup + -- * BufReadPre: this will be triggered early when opening a file from the command line directly + disable_events = { "VimEnter", "BufReadPre" }, } M.debug = false @@ -40,15 +39,10 @@ function M.check_load(modname, modpath) require("lazy.core.loader").autoload(modname, modpath) end ----@param step? string -function M.disable(step) +function M.disable() if not M.enabled then return end - if step and M.config.strategy ~= step then - return - end - local idx = M.idx() if idx then table.remove(package.loaders, idx) @@ -141,17 +135,8 @@ function M.setup(opts) M.load_cache() table.insert(package.loaders, M.loader_idx, M.loader) - if M.config.strategy == "VimEnter" then - vim.api.nvim_create_autocmd("VimEnter", { - once = true, - callback = function() - -- use schedule so all other VimEnter handlers will have run - vim.schedule(function() - -- startup done, so stop caching - M.disable() - end) - end, - }) + if #M.config.disable_events > 0 then + vim.api.nvim_create_autocmd(M.config.disable_events, { once = true, callback = M.disable }) end return M end diff --git a/lua/lazy/init.lua b/lua/lazy/init.lua index 1883d82..103bffe 100644 --- a/lua/lazy/init.lua +++ b/lua/lazy/init.lua @@ -8,10 +8,9 @@ function M.setup(spec, opts) end local start = vim.loop.hrtime() - local Cache if not (opts and opts.performance and opts.performance.cache and opts.performance.cache.enabled == false) then -- load module cache before anything else - Cache = require("lazy.core.cache").setup(opts) + require("lazy.core.cache").setup(opts) end local Util = require("lazy.core.util") @@ -40,17 +39,9 @@ function M.setup(spec, opts) Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" } end - if Cache then - Cache.disable("lazy") - end - -- load plugins with lazy=false or Plugin.init Loader.init_plugins() - if Cache then - Cache.disable("init") - end - -- all done! vim.cmd("do User LazyDone") end