JoosepAlviste/nvim-ts-context-commentstring

Invalid comment string in jsx, multiline exprassion inside `{}`

MuhammadSawalhy opened this issue · 2 comments

Here is the current commentsting:

image

Here is what I expected:

image

Hey @MuhammadSawalhy, thanks for the bug report!

I added an extra rule for this exact use-case, but in general, it's a bit tricky to detect similar multi-line expressions inside {} with the current logic. I think that it would require thinking through the problem a bit more.

Together with the {}, the treesitter node is called jsx_expression but we can't really configure jsx_expression: '// %s', because then commenting a single-line expression would be incorrect. The first idea I had was that we could detect if the parent of a node is jsx_expression. We could have a hypothetical configuration like so:

javascript = {
  __default = '// %s',
  jsx_element = '{/* %s */}',
  jsx_fragment = '{/* %s */}',
  jsx_attribute = '// %s',
  comment = '// %s',
  __parent = {
    -- if a node has this as the parent, use the `//` commentstring
    jsx_expression = '// %s',
  },
}

Anyways, I'm not sure if I'll have time to implement this soon. Hopefully the current fix is good enough for now 😄

tbo commented

I've got a similar issue with html string literals:

Screen Shot 2022-04-03 at 11 57 44