JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.13k stars 34 forks source link

feat: add basic templ support #98

Closed tommsawyer closed 2 months ago

tommsawyer commented 5 months ago

Added basic support for templ files. Docs for templ commenting here: https://templ.guide/syntax-and-usage/comments

In general we are using html-style comments inside components, and go-style comments outside.

haydenrou commented 5 months ago

Something like this would be awesome out of the box, thanks!

I've added the solution to my own dotfiles here for the time-being. It works great except for one thing - the templ builtin function templ myComponent() { will be commented like <!-- templ myComponent() { -->. Is that something we could accommodate for?

JoosepAlviste commented 5 months ago

Hey, thanks for the PR! Supporting templ makes a lot of sense since it seems to be very similar to JSX.

In order to handle the templ myComponent() { line correctly, I think that we can use component_block instead of component_declaration as the node.

If we wanted to have a bit more robust support for templ, then we could also handle this case (but it's probably not required yet). What should happen in the following lines?

package main

templ hello(name string) {
    <div>
        <h1>Howdy foks</h1>
        Hello, { name }

        <hr style="padding: 10px"
            if true {  <-- this line, for example, and the next one
                class="itIsTrue"
            }
        />
    </div>
}

Here's how it would work with component_block:

https://github.com/JoosepAlviste/nvim-ts-context-commentstring/assets/9450943/516e05d6-ef4f-4f50-96e2-a4eef6ec7124

zyriab commented 2 months ago

Hello! Any plan to merge this PR soon? :)

JoosepAlviste commented 2 months ago

Merged and pushed the small fix myself, thanks for the reminder 👍