Screen.Recording.2024-09-22.033530.mp4
Spits out a print statement for different languages. I myself am a print debugger, and find it tedious to always write print('data from somewhere', data) Therefore, I found myself writing a similar code to what is in here to my config.
Thought I'd create a plugin for it to keep it separated from my config.
Currently supported languages are:
- JavaScript and JSReact
- TypeScript and TSReact
- Python
- Lua
- Go
- Rust
- Bash Script
I use these mostly, therefore created it for them for now.
return {
"OmerBilgin21/print-debugger.nvim",
config = function()
require("print-debugger").setup({
keymaps = {
"<C-g>",
},
})
end,
}use({
"OmerBilgin21/print-debugger.nvim",
config = function()
require("print-debugger").setup({
keymaps = {
"<C-g>",
},
})
end,
})Plug 'OmerBilgin21/print-debugger.nvim'
lua << EOF
require('print-debugger').setup({
keymaps = {
"<C-g>",
},
})
EOFYou can override the logger function and argument style per filetype.
require("print-debugger").setup({
go = {
prefix = "util.Log", -- replaces fmt.Printf
spread_mode = true, -- util.Log("x: ", x) instead of formatted string
},
javascript = {
prefix = "logger.info", -- replaces console.log
},
keymaps = {
"<C-g>",
},
})prefixreplaces the default logging function for that language.spread_mode(Go only) disables formatting and passes arguments directly.
Example (Go):
util.Log("tokenString: ", tokenString)
Or, if you would like to define your own keymaps, the debug_function is exposed via print-debugger module.
Meaning this would also work:
vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Go to Left Window", remap = true })If you go with the solution above, you then do not need to call the setup function.
Caution: This will break on data types that do not implement the Debug trait for Rust.
(I do not know Rust; PRs welcome.)