Closed andrewferrier closed 9 months ago
I know you had set this to console.warn
but this sometimes muddies the console as seen In the pic. If you default to console.log
, it should suffice for everything under the JS umbrella.
vs
@CarlosMed hmm, this is a tricky one. JavaScript is not just used in browsers, but in NodeJS and other runtimes too, so I'm cautious about optimising for the browser use case by creating an exception from the usual principle of making DEBUGPRINT stand out, common though it might be. Is that the default behaviour of your browser?
As far as I know, NodeJS also has a console.log as well as DenoJS and BunJS. On the above with console.warn
it throws in way too much info that's unnecessary. The only way I guess to appease people would be to make the console more agnostic where It can be changed in the config from log or warn.
@CarlosMed so I've done some testing of console.log()
, console.warn()
, console.debug()
and console.error()
:
On NodeJS, they all display the same by default, except that warn
and error
go to stderr (which I consider desirable, albeit not essential, following the principles here.
On Firefox (Librewolf 121.0 to be precise), it displays log
and debug
in plain text, with warn
in yellow text, and error
in red text. None of the logging lines are 'expanded' in the way you show.
On Chrome (121), it displays 'log', 'warn', and 'error' by default, with warn in yellow and error in red by default. Again, all of the logging lines are just single lines and not 'expanded'.
I can't recreate what you are showing in your screenshots. My guess would be (I don't do much browser JavaScript) that you are logging an variable/object with a stacktrace called 'error', in which case it makes sense (I think) that it's expanded.
So I'm unclear what issue you're referring to when you say 'way too much info' - from my testing it seems like it's the same level of info whichever console method you use. Can you provide some more specific recreation instructions?
Of course, remember you can always override the behaviour in any event in your own config as described here. If you specify an existing filetype, it will override the behaviour for that filetype.
The above solved my issue. Since it makes it flexible. Thank you!
OK, thanks. I'm closing this issue since I can't recreate the specific problem you described and it sounds like you've fixed with changes to your own config. Thanks for your contribution!
For those who followed by console.warn
issuse, if you use javascript and typescript (and react) maybe you should set whole languages like below.
I'm changed console.warn
-> console.info
by this setting. (in lazyvim)
return {
{
"andrewferrier/debugprint.nvim",
config = function()
require("debugprint").setup({
filetypes = {
["js"] = {
left = 'console.info("',
right = '")',
mid_var = '", ',
right_var = ")",
},
["javascript"] = {
left = 'console.info("',
right = '")',
mid_var = '", ',
right_var = ")",
},
["javascriptreact"] = {
left = 'console.info("',
right = '")',
mid_var = '", ',
right_var = ")",
},
["typescript"] = {
left = 'console.info("',
right = '")',
mid_var = '", ',
right_var = ")",
},
["typescriptreact"] = {
left = 'console.info("',
right = '")',
mid_var = '", ',
right_var = ")",
},
},
})
end,
version = "*",
},
}
Thanks @tolluset! I'll keep the default will stay at console.warn()
for now, given the investigation above, unless someone can give a compelling reason otherwise, but I am considering creating a semi-official 'showcase' of alternative debugprint
setups, and I might adapt something like this into that showcase. Thanks for the heads-up.
By the way, you can do this a bit more efficiently like this:
local js_like = { left = 'console.info("', right = '")', mid_var = '", ', right_var = ")", } return { { "andrewferrier/debugprint.nvim", config = function() require("debugprint").setup({ filetypes = { ["javascript"] = js_like, ["javascriptreact"] = js_like, ["typescript"] = js_like, ["typescriptreact"] = js_like, }, }) end, version = "*", }, }
Oh, and just a heads-up @tolluset - js
isn't a valid filetype in NeoVim, I believe - it's javascript
.
Thanks @tolluset! I'll keep the default will stay at
console.warn()
for now, given the investigation above, unless someone can give a compelling reason otherwise, but I am considering creating a semi-official 'showcase' of alternativedebugprint
setups, and I might adapt something like this into that showcase. Thanks for the heads-up.By the way, you can do this a bit more efficiently like this:
local js_like = { left = 'console.info("', right = '")', mid_var = '", ', right_var = ")", } return { { "andrewferrier/debugprint.nvim", config = function() require("debugprint").setup({ filetypes = { ["javascript"] = js_like, ["javascriptreact"] = js_like, ["typescript"] = js_like, ["typescriptreact"] = js_like, }, }) end, version = "*", }, }
This way looks great!! Thanks!!! ☺️
This way looks great!! Thanks!!! ☺️
FYI - I'm now starting to track configurations such as this in a showcase.
https://www.reddit.com/r/neovim/comments/1848aoc/comment/kaw948m/?utm_source=share&utm_medium=web2x&context=3