andrewferrier / debugprint.nvim

Debugging in NeoVim the print() way!
MIT License
355 stars 22 forks source link

Consider changing console.debug to console.log #72

Closed andrewferrier closed 9 months ago

andrewferrier commented 12 months ago

https://www.reddit.com/r/neovim/comments/1848aoc/comment/kaw948m/?utm_source=share&utm_medium=web2x&context=3

andrewferrier commented 12 months ago

This has been done: https://github.com/andrewferrier/debugprint.nvim/commit/c8341fddca633ffe8b50474601c3651f260dbeed.

CarlosMed commented 10 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.

image

vs

image
andrewferrier commented 10 months ago

@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?

CarlosMed commented 10 months ago

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.

andrewferrier commented 10 months ago

@CarlosMed so I've done some testing of console.log(), console.warn(), console.debug() and console.error():

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.

CarlosMed commented 10 months ago

The above solved my issue. Since it makes it flexible. Thank you!

andrewferrier commented 9 months ago

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!

tolluset commented 3 months ago

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 = "*",
  },
}
andrewferrier commented 3 months ago

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 = "*",
  },
}
andrewferrier commented 3 months ago

Oh, and just a heads-up @tolluset - js isn't a valid filetype in NeoVim, I believe - it's javascript.

tolluset commented 3 months ago

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 = "*",
  },
}

This way looks great!! Thanks!!! ☺️

andrewferrier commented 3 months ago

This way looks great!! Thanks!!! ☺️

FYI - I'm now starting to track configurations such as this in a showcase.