diff --git a/lua/noice/util/init.lua b/lua/noice/util/init.lua index b1cf8ba..72069eb 100644 --- a/lua/noice/util/init.lua +++ b/lua/noice/util/init.lua @@ -323,15 +323,22 @@ function M.info(msg, ...) M.notify(msg, vim.log.levels.INFO, ...) end +---@param data any function M.debug(data) + if not Config.options.debug then + return + end + if type(data) == "function" then + data = data() + end + if type(data) ~= "string" then + data = vim.inspect(data) + end local file = "./noice.log" local fd = io.open(file, "a+") if not fd then error(("Could not open file %s for writing"):format(file)) end - if type(data) ~= "string" then - data = vim.inspect(data) - end fd:write(data .. "\n") fd:close() end diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index 3b5504c..0bbccc2 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -134,6 +134,13 @@ function View:set(messages, opts) self:push(messages, opts) end +function View:debug(msg) + if Config.options.debug then + Util.debug(("[%s] %s"):format(self._opts.view, vim.inspect(msg))) + Util.debug(debug.traceback()) + end +end + -- Safely destroys any create windows and buffers. -- This is needed to properly re-create views in case of E565 errors function View:destroy() end @@ -148,7 +155,8 @@ function View:display() self:show() self._errors = 0 end, { - catch = function() + catch = function(err) + self:debug(err) self:destroy() end, })()