helix icon indicating copy to clipboard operation
helix copied to clipboard

Comments in JSX/TSX

Open cotneit opened this issue 5 months ago • 0 comments

Comments in JSX are a bit special, and it would be nice if Helix could handle them a bit better than it does now when it comes to commenting and uncommenting.

JS comments (// and /* */) are not valid where a JSXChild is expected, but they become valid when wrapped in curly braces {} since then they are treated as JSXChildExpression, and it being optional the entire thing can be a comment, resulting in {/* */} essentially being a block comment token pair for this particular case.

In every other case inside a JSX file regular JS comments are valid and should be preferred over {/* */}.

For example, every comment here is valid:

const Thingy = <>
    {/* <div></div> */}

    <div
        // id="main" style="color: blue"
        /* id="main" style="color: red" */

        thingy={
            // <div></div>
            <div>
                {/* <div>Lorem</div> */}
            </div>
        }
    >
        {/* <div>Lorem</div> */}
    </div>
</>

Looks like VS Code implements this by injecting a special language:

I imagine this could be replicated in Helix, but currently injection comment tokens are ignored, so I would consider this to be blocked:

  • https://github.com/helix-editor/helix/issues/7364
  • https://github.com/helix-editor/helix/issues/9425

That said, I don't think these issues being resolved will result in JSX/TSX comments working properly without additional efforts, hence this issue. I could be wrong.


Prior issues on this topic:

  • https://github.com/helix-editor/helix/issues/6832
  • https://github.com/helix-editor/helix/issues/7731
  • https://github.com/helix-editor/helix/issues/5453

cotneit avatar Sep 06 '24 18:09 cotneit