From e4cf8b141681657922643e70ec21b9f9133e9fca Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 2 Dec 2022 16:52:22 +0100 Subject: [PATCH] feat: added debug option --- lua/lazy/core/cache.lua | 10 +++++++--- lua/lazy/core/config.lua | 1 + lua/lazy/core/util.lua | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index a1ff4126..551409d2 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -17,6 +17,7 @@ M.config = { -- * allthethings: all mdules. Not recommended strategy = "VimEnter", ---@type "lazy"|"init"|"VimEnter"|"allthethings" } +M.debug = false ---@type CacheHash local cache_hash @@ -82,9 +83,11 @@ function M.loader(modname) M.cache[modname] = entry end end - vim.schedule(function() - vim.notify("loading " .. modname) - end) + if M.debug then + vim.schedule(function() + vim.notify("[cache:load] " .. modname) + end) + end if entry and chunk then M.dirty = true entry.chunk = string.dump(chunk) @@ -130,6 +133,7 @@ function M.setup(opts) M.config[k] = v end end + M.debug = opts and opts.debug M.load_cache() table.insert(package.loaders, M.loader_idx, M.loader) diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 374ed54f..6988342d 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -52,6 +52,7 @@ M.defaults = { cache = nil, reset_packpath = true, -- packpath will be reset to only include lazy. This makes packadd a lot faster }, + debug = false, } M.ns = vim.api.nvim_create_namespace("lazy") diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index e29029b8..fb93edda 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -159,7 +159,9 @@ function M.lsmod(root, fn) end) end +---@param msg string|string[] function M.notify(msg, level) + msg = type(msg) == "table" and table.concat(msg, "\n") or msg vim.notify(msg, level, { on_open = function(win) vim.wo[win].conceallevel = 3 @@ -172,12 +174,19 @@ function M.notify(msg, level) }) end +---@param msg string|string[] function M.error(msg) M.notify(msg, vim.log.levels.ERROR) end +---@param msg string|string[] function M.info(msg) M.notify(msg, vim.log.levels.INFO) end +---@param msg string|string[] +function M.warn(msg) + M.notify(msg, vim.log.levels.WARN) +end + return M