docs/debug.md
Utility functions you can use in your code.
Personally, I have the code below at the top of my init.lua:
_G.dd = function(...)
Snacks.debug.inspect(...)
end
_G.bt = function()
Snacks.debug.backtrace()
end
if vim.fn.has("nvim-0.11") == 1 then
vim._print = function(_, ...)
dd(...)
end
else
vim.print = dd
end
What this does:
dd(...) you can use anywhere to quickly show a
notification with a pretty printed dump of the object(s)
with lua treesitter highlightingbt() to show a notification with a pretty
backtrace.vim.print, which is also used by := {something = 123}---@class snacks.debug.cmd
---@field cmd string|string[]
---@field level? snacks.notifier.level|vim.log.levels
---@field title? string
---@field args? string[]
---@field cwd? string
---@field group? boolean
---@field notify? boolean
---@field footer? string
---@field header? string
---@field props? table<string, string|boolean|number|nil>
---@alias snacks.debug.Trace {name: string, time: number, [number]:snacks.debug.Trace}
---@alias snacks.debug.Stat {name:string, time:number, count?:number, depth?:number}
Snacks.debug()---@type fun(...)
Snacks.debug()
Snacks.debug.backtrace()Show a notification with a pretty backtrace
---@param msg? string|string[]
---@param opts? snacks.notify.Opts
Snacks.debug.backtrace(msg, opts)
Snacks.debug.cmd()---@param opts snacks.debug.cmd
Snacks.debug.cmd(opts)
Snacks.debug.inspect()Show a notification with a pretty printed dump of the object(s) with lua treesitter highlighting and the location of the caller
Snacks.debug.inspect(...)
Snacks.debug.log()Log a message to the file ./debug.log.
vim.inspect.Snacks.debug.log("Hello", { foo = "bar" }, 42)
-- 2024-11-08 08:56:52 Hello { foo = "bar" } 42
Snacks.debug.log(...)
Snacks.debug.metrics()Snacks.debug.metrics()
Snacks.debug.profile()Very simple function to profile a lua function.
true to use jit.flush in every iteration.---@param fn fun()
---@param opts? {count?: number, flush?: boolean, title?: string}
Snacks.debug.profile(fn, opts)
Snacks.debug.run()Run the current buffer or a range of lines.
Shows the output of print inlined with the code.
Any error will be shown as a diagnostic.
---@param opts? {name?:string, buf?:number, print?:boolean}
Snacks.debug.run(opts)
Snacks.debug.size()Snacks.debug.size(bytes)
Snacks.debug.stats()---@param opts? {min?: number, show?:boolean}
---@return {summary:table<string, snacks.debug.Stat>, trace:snacks.debug.Stat[], traces:snacks.debug.Trace[]}
Snacks.debug.stats(opts)
Snacks.debug.trace()---@param name string?
Snacks.debug.trace(name)
Snacks.debug.tracemod()---@param modname string
---@param mod? table
---@param suffix? string
Snacks.debug.tracemod(modname, mod, suffix)