Comment.nvim icon indicating copy to clipboard operation
Comment.nvim copied to clipboard

Proposal for JSX/TSX support

Open mmkaram opened this issue 10 months ago • 3 comments

Hello,

I was wondering if I could attempt to implement a working commenting system for inline jsx/tsx. I wanted to add this first because it's explicitly stated in the readme that this was difficult to implement, and I wanted to make sure this kind of contribution is welcome.

Thanks!

mmkaram avatar Feb 11 '25 20:02 mmkaram

I just started looking into this as well. I found this reddit comment with a solution that uses nvim-ts-context-commentstring which I removed a while ago since Comment.nvim already supports injected languages:

treesitter.setup({
  context_commentstring = {
    config = {
       javascript = {
          __default = '// %s',
          jsx_element = '{/* %s */}',
          jsx_fragment = '{/* %s */}',
          jsx_attribute = '// %s',
          comment = '// %s',
       },
       typescript = { __default = '// %s', __multiline = '/* %s */' },
   },

-- ...

comment.setup({
   pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
-- ...

I think the problem is that jsx/tsx elements aren't an injected language in treesitter.

Not sure if that's of any help.

mawkler avatar Feb 13 '25 09:02 mawkler

@herloncosta That is VimScript my friend

mawkler avatar Feb 22 '25 07:02 mawkler

yes!

jellli avatar Feb 22 '25 08:02 jellli