mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
1.3 KiB
1.3 KiB
🍿 debug
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
vim.print = _G.dd
What this does:
- Add a global
dd(...)you can use anywhere to quickly show a notification with a pretty printed dump of the object(s) with lua treesitter highlighting - Add a global
bt()to show a notification with a pretty backtrace. - Override Neovim's
vim.print, which is also used by:= {something = 123}
📦 Module
Snacks.debug()
---@type fun(...)
Snacks.debug()
Snacks.debug.backtrace()
Show a notification with a pretty backtrace
Snacks.debug.backtrace()
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.profile()
Very simple function to profile a lua function.
- flush: set to
trueto usejit.flushin every iteration. - count: defaults to 100
---@param fn fun()
---@param opts? {count?: number, flush?: boolean}
Snacks.debug.profile(fn, opts)