tree-sitter-templ icon indicating copy to clipboard operation
tree-sitter-templ copied to clipboard

Syntax highlighting boke after using a component which has a child with NVIM.

Open vighd opened this issue 9 months ago • 5 comments

Hi!

With the latest version of this project, my syntax highlighting is failing when I using a component with another one inside. I seen a similar closed issue which one is should be fix this, but that fix is not working for me.

For test environment, I used the recommended minimal NVIM configuration from the templ guide.

The current version of this project highlight my code like this:

20240511_09h53m54s_grim

If I remove the @ character, the highlighting works again like this:

20240511_09h54m28s_grim

vighd avatar May 11 '24 08:05 vighd

Hi,

a quick test show we don't handle import expressions using the form

@Foo{

}

right the now parser thinks the { starts a new block and it breaks parsing.

Can you share the code of components.FieldControl and components.Select to make it easier for me to debug ?

vrischmann avatar May 12 '24 07:05 vrischmann

Of course, here you go:

package components

type Select struct {
    Values      []SelectValues
    Class       string
    Selected    string
    Placeholder string
    Attrs       templ.Attributes
}

type SelectValues struct {
    Value string
    Data  string
}

templ (i Select) Select() {
    <div class="select is-fullwidth">
        <select { i.Attrs... }>
            for k, v := range i.Values {
                if k == 0 && i.Placeholder != "" {
                    <option selected?={ i.Selected=="" } disabled value="">{ i.Placeholder }</option>
                }
                <option selected?={ v.Value==i.Selected } value={ v.Value }>{ v.Data }</option>
            }
        </select>
    </div>
}
package components

templ FieldControl(label string) {
    <div class="field">
        <label class="label">{ label }</label>
        <div class="control">
            { children... }
        </div>
    </div>
}

vighd avatar May 12 '24 08:05 vighd

Hi,

a quick test show we don't handle import expressions using the form

@Foo{

}

right the now parser thinks the { starts a new block and it breaks parsing.

Can you share the code of components.FieldControl and components.Select to make it easier for me to debug ?

Stumbled on this:

right the now parser thinks the { starts a new block and it breaks parsing.

Is there any news?

I'm trying something similar, but with inconsistencies.

image

Edit:

Could you point me on the files that would need to be modified to extend the parser? I've never touched tree-sitter stuff, got some tiny c + compiler/parser experience, maybe I could give a hand

Odas0R avatar Jun 06 '24 21:06 Odas0R

Hi, I started working on this a while ago in this branch: https://github.com/vrischmann/tree-sitter-templ/tree/fix-import-expression-brace but IIRC it doesn't work and I didn't touch it since then.

I don't have time right now to work on this, if you want to work on this feel free to base your work on my branch.

vrischmann avatar Jun 10 '24 10:06 vrischmann

Okay, will look into it when I have the chance :)

Thank you

Odas0R avatar Jun 10 '24 11:06 Odas0R