diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index c05c0af..eee6b16 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -101,14 +101,31 @@ function M.disable() if not M.enabled then return end - if M.debug and vim.tbl_count(M.topmods) > 1 then - vim.schedule(function() - vim.notify("topmods:\n" .. vim.inspect(M.topmods), vim.log.levels.WARN, { title = "lazy.nvim" }) - end) - end -- selene:allow(global_usage) _G.loadfile = M._loadfile M.enabled = false + if M.debug and vim.tbl_count(M.topmods) > 1 then + M.log(M.topmods, vim.log.levels.WARN, { title = "topmods" }) + end + if M.debug then + local stats = vim.deepcopy(M.stats) + stats.time = (stats.time or 0) / 1e6 + stats.find.time = (stats.find.time or 0) / 1e6 + stats.autoload.time = (stats.autoload.time or 0) / 1e6 + M.log(stats, nil, { title = "stats" }) + end +end + +---@param msg string|table +---@param level? number +---@param opts? {lang?:string, title?:string} +function M.log(msg, level, opts) + if M.debug then + msg = vim.deepcopy(msg) + vim.schedule(function() + require("lazy.core.util").debug(msg, level, opts) + end) + end end function M.check_loaded(modname) @@ -191,9 +208,7 @@ function M.load(modkey, modpath) entry.hash = hash if M.debug then - vim.schedule(function() - vim.notify("[cache:load] " .. modpath) - end) + M.log("`" .. modpath .. "`", nil, { title = "Cache.load" }) end chunk, err = M._loadfile(entry.modpath) diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index e39d3d8..31acdec 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -216,7 +216,16 @@ function M.lsmod(modname, fn) end ---@param msg string|string[] -function M.notify(msg, level) +---@param opts? {lang?:string, title?:string} +function M.notify(msg, level, opts) + if vim.in_fast_event() then + vim.schedule(function() + M.notify(msg, level, opts) + end) + return + end + + opts = opts or {} if type(msg) == "table" then msg = table.concat( vim.tbl_filter(function(line) @@ -225,17 +234,20 @@ function M.notify(msg, level) "\n" ) end + local lang = opts.lang or "markdown" vim.notify(msg, level, { on_open = function(win) + pcall(require, "nvim-treesitter") vim.wo[win].conceallevel = 3 vim.wo[win].concealcursor = "" vim.wo[win].spell = false local buf = vim.api.nvim_win_get_buf(win) - if not pcall(vim.treesitter.start, buf, "markdown") then - vim.bo[buf].filetype = "markdown" + if not pcall(vim.treesitter.start, buf, lang) then + vim.bo[buf].filetype = lang + vim.bo[buf].syntax = lang end end, - title = "lazy.nvim", + title = "lazy.nvim" .. (opts.title and ": " .. opts.title or ""), }) end @@ -254,4 +266,20 @@ function M.warn(msg) M.notify(msg, vim.log.levels.WARN) end +---@param msg string|table +---@param level? number +---@param opts? {lang?:string, title?:string} +function M.debug(msg, level, opts) + if not require("lazy.core.config").options.debug then + return + end + opts = opts or {} + if type(msg) == "string" then + M.notify(msg, level) + else + opts.lang = "lua" + M.notify(vim.inspect(msg), level, opts) + end +end + return M diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index d24794f..793e832 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -110,6 +110,7 @@ function M.open_cmd(cmd, opts) buffer = float.buf, callback = function() float:close() + vim.cmd.checktime() end, }) end