JoosepAlviste/nvim-ts-context-commentstring

Toggling comment of a first line of JSX in a block does not work

JoosepAlviste opened this issue · 3 comments

If I comment out twice in tsx, it will behave strangely.

CleanShot 2021-06-03 at 00 59 55@2x
require("kommentary.config").configure_language("typescriptreact", {
    hook_function = function()
       pre_comment_hook = require('ts_context_commentstring.internal').update_commentstring()
    end,
    prefer_single_line_comments = true,
})

The issue is that if you comment the first line (only the first line) in any JSX block, then there will be a syntax error. For example, this is not valid JS/JSX:

const App = () => (
  {/* <div> */}
    <p>Hello world</p>
  </div>
)

Now, treesitter thinks that the first line of JSX with the comment is an object.

But I don't think that it's super high priority for now. I probably won't be dealing with it any time soon.

Initial issue from here: #10 (comment)

I came across this bug today too, is this in essence, an issue that needs to be fixed in TreeSitter?

Hey @sparkbuzz!

I don't think that this is a problem with treesitter because it makes sense that it can't parse the commented code, it's not actually valid syntax. So, I think that something should still be added to this plugin to handle the weird treesitter syntax tree, but it probably requires being able to write more complex configuration for commentstrings.

But there might be another good solution, I haven't given this issue too much thought.

I'll close this in favor of #29 since that one has more information.