mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
85 lines
2.6 KiB
Text
85 lines
2.6 KiB
Text
*snacks-debug.txt* For Neovim Last change: 2024 November 07
|
||
|
||
==============================================================================
|
||
Table of Contents *snacks-debug-table-of-contents*
|
||
|
||
1. Module |snacks-debug-module|
|
||
- Snacks.debug() |snacks-debug-module-snacks.debug()|
|
||
- Snacks.debug.backtrace() |snacks-debug-module-snacks.debug.backtrace()|
|
||
- Snacks.debug.inspect() |snacks-debug-module-snacks.debug.inspect()|
|
||
- Snacks.debug.profile() |snacks-debug-module-snacks.debug.profile()|
|
||
2. Links |snacks-debug-links|
|
||
Utility functions you can use in your code.
|
||
|
||
Personally, I have the code below at the top of my `init.lua`
|
||
|
||
>lua
|
||
_G.dd = function(...)
|
||
Snacks.debug.inspect(...)
|
||
end
|
||
_G.bt = function()
|
||
Snacks.debug.backtrace()
|
||
end
|
||
vim.print = _G.dd
|
||
<
|
||
|
||
Whatthis 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}`
|
||
|
||
|
||
==============================================================================
|
||
1. Module *snacks-debug-module*
|
||
|
||
|
||
SNACKS.DEBUG() *snacks-debug-module-snacks.debug()*
|
||
|
||
>lua
|
||
---@type fun(...)
|
||
Snacks.debug()
|
||
<
|
||
|
||
|
||
SNACKS.DEBUG.BACKTRACE() *snacks-debug-module-snacks.debug.backtrace()*
|
||
|
||
Show a notification with a pretty backtrace
|
||
|
||
>lua
|
||
Snacks.debug.backtrace()
|
||
<
|
||
|
||
|
||
SNACKS.DEBUG.INSPECT() *snacks-debug-module-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
|
||
|
||
>lua
|
||
Snacks.debug.inspect(...)
|
||
<
|
||
|
||
|
||
SNACKS.DEBUG.PROFILE() *snacks-debug-module-snacks.debug.profile()*
|
||
|
||
Very simple function to profile a lua function. **flush**set to `true` to use
|
||
`jit.flush` in every iteration. **count**defaults to 100
|
||
|
||
>lua
|
||
---@param fn fun()
|
||
---@param opts? {count?: number, flush?: boolean}
|
||
Snacks.debug.profile(fn, opts)
|
||
<
|
||
|
||
==============================================================================
|
||
2. Links *snacks-debug-links*
|
||
|
||
1. *image*: https://github.com/user-attachments/assets/0517aed7-fbd0-42ee-8058-c213410d80a7
|
||
|
||
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
|
||
|
||
vim:tw=78:ts=8:noet:ft=help:norl:
|