feat: added debug option

This commit is contained in:
Folke Lemaitre 2022-12-02 16:52:22 +01:00
parent fe6b0b03ea
commit e4cf8b1416
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 17 additions and 3 deletions

View File

@ -17,6 +17,7 @@ M.config = {
-- * allthethings: all mdules. Not recommended -- * allthethings: all mdules. Not recommended
strategy = "VimEnter", ---@type "lazy"|"init"|"VimEnter"|"allthethings" strategy = "VimEnter", ---@type "lazy"|"init"|"VimEnter"|"allthethings"
} }
M.debug = false
---@type CacheHash ---@type CacheHash
local cache_hash local cache_hash
@ -82,9 +83,11 @@ function M.loader(modname)
M.cache[modname] = entry M.cache[modname] = entry
end end
end end
vim.schedule(function() if M.debug then
vim.notify("loading " .. modname) vim.schedule(function()
end) vim.notify("[cache:load] " .. modname)
end)
end
if entry and chunk then if entry and chunk then
M.dirty = true M.dirty = true
entry.chunk = string.dump(chunk) entry.chunk = string.dump(chunk)
@ -130,6 +133,7 @@ function M.setup(opts)
M.config[k] = v M.config[k] = v
end end
end end
M.debug = opts and opts.debug
M.load_cache() M.load_cache()
table.insert(package.loaders, M.loader_idx, M.loader) table.insert(package.loaders, M.loader_idx, M.loader)

View File

@ -52,6 +52,7 @@ M.defaults = {
cache = nil, cache = nil,
reset_packpath = true, -- packpath will be reset to only include lazy. This makes packadd a lot faster 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") M.ns = vim.api.nvim_create_namespace("lazy")

View File

@ -159,7 +159,9 @@ function M.lsmod(root, fn)
end) end)
end end
---@param msg string|string[]
function M.notify(msg, level) function M.notify(msg, level)
msg = type(msg) == "table" and table.concat(msg, "\n") or msg
vim.notify(msg, level, { vim.notify(msg, level, {
on_open = function(win) on_open = function(win)
vim.wo[win].conceallevel = 3 vim.wo[win].conceallevel = 3
@ -172,12 +174,19 @@ function M.notify(msg, level)
}) })
end end
---@param msg string|string[]
function M.error(msg) function M.error(msg)
M.notify(msg, vim.log.levels.ERROR) M.notify(msg, vim.log.levels.ERROR)
end end
---@param msg string|string[]
function M.info(msg) function M.info(msg)
M.notify(msg, vim.log.levels.INFO) M.notify(msg, vim.log.levels.INFO)
end end
---@param msg string|string[]
function M.warn(msg)
M.notify(msg, vim.log.levels.WARN)
end
return M return M