helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.84k stars 2.51k forks source link

Comments in JSX/TSX #11647

Open cotneit opened 2 months ago

cotneit commented 2 months ago

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:

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:

Nikita0x commented 2 months ago

I don't want to create a new issue, just gonna leave it here maybe?

Comments are incorrectly inferred in Vue.js (.vue) files as well incorrect comment

DoctorRyner commented 1 month ago

It's really annoying that I can't properly comment big chunks of html in jsx files

Nikita0x commented 1 month ago

It's really annoying that I can't properly comment big chunks of html in jsx files

They're working on it, here:

DoctorRyner commented 1 month ago

@Nikita0x oh, I hope so. Because there are less and less commits with any changes