Skip to content

Commit

Permalink
feat: capture generic function declarations (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav authored May 30, 2024
1 parent 913c9b8 commit 4f85ade
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 83 deletions.
19 changes: 17 additions & 2 deletions syntaxes/templ.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
]
},
"html-template": {
"begin": "^(templ) ((?:\\([A-z_][A-z_0-9]* \\*?[A-z_][A-z_0-9]*\\) )?[A-z_][A-z_0-9]*\\()",
"begin": "^(templ) ((?:\\([A-z_][A-z_0-9]* \\*?[A-z_][A-z_0-9]*\\) )?[A-z_][A-z_0-9]*(\\(|\\[))",
"beginCaptures": {
"1": {
"name": "keyword.control.go"
Expand Down Expand Up @@ -200,6 +200,21 @@
}
]
},
{
"name": "type-params.html-template.templ",
"begin": "(?<=\\[)",
"end": "(\\])",
"endCaptures": {
"1": {
"name": "punctuation.definition.end.bracket.square.go"
}
},
"patterns": [
{
"include": "source.go"
}
]
},
{
"name": "block.html-template.templ",
"begin": "(?<=\\)) ({)$",
Expand Down Expand Up @@ -1093,4 +1108,4 @@
]
}
}
}
}
22 changes: 11 additions & 11 deletions tests/snap/complex_syntax.templ
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ templ (d Data) Method(greeting string) {
}

templ test(comp templ.Component) {
<div>
@comp {
<div>Children</div>
}
</div>
<div>
@comp {
<div>Children</div>
}
</div>
}

templ Hello() {
templ Hello[T ~string]() {
@Data{
message: "You can implement methods on a type.",
message: "You can implement methods on a type.",
}.Method("hello") {
@test(Data{ message: "You can implement methods on a type." }.Method("hello"))
<div>
{ children... }
</div>
@test(Data{message: "You can implement methods on a type."}.Method("hello"))
<div>
{ children... }
</div>
}
}
143 changes: 73 additions & 70 deletions tests/snap/complex_syntax.templ.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,92 +66,95 @@
# ^ source.templ html-template.templ params.html-template.templ punctuation.definition.end.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ punctuation.definition.begin.bracket.curly.go
> <div>
#^^^^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.begin.html
# ^^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html entity.name.tag.block.any.html
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.end.html
> @comp {
#^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ
# ^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ start.string-expression.templ
> <div>Children</div>
#^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
> <div>
#^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.begin.html
# ^^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html entity.name.tag.block.any.html
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.end.html
> @comp {
#^^^^^^^^ source.templ html-template.templ block.html-template.templ
# ^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ start.string-expression.templ
> <div>Children</div>
#^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.arithmetic.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
> }
#^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ end.string-expression.templ
> </div>
#^^^^ source.templ html-template.templ block.html-template.templ
# ^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.begin.html
# ^^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html entity.name.tag.block.any.html
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.end.html
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.arithmetic.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
> }
#^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ end.string-expression.templ
> </div>
#^ source.templ html-template.templ block.html-template.templ
# ^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.begin.html
# ^^^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html entity.name.tag.block.any.html
# ^ source.templ html-template.templ block.html-template.templ meta.tag.block.any.html punctuation.definition.tag.end.html
>}
#^ source.templ html-template.templ block.html-template.templ punctuation.definition.end.bracket.curly.go
>
>templ Hello() {
>templ Hello[T ~string]() {
#^^^^^ source.templ html-template.templ keyword.control.go
# ^ source.templ html-template.templ
# ^^^^^ source.templ html-template.templ
# ^ source.templ html-template.templ punctuation.definition.begin.bracket.round.go
# ^ source.templ html-template.templ params.html-template.templ punctuation.definition.end.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ punctuation.definition.begin.bracket.curly.go
# ^ source.templ html-template.templ punctuation.definition.bracket.square.go
# ^^^ source.templ html-template.templ type-params.html-template.templ
# ^^^^^^ source.templ html-template.templ type-params.html-template.templ storage.type.string.go
# ^ source.templ html-template.templ type-params.html-template.templ punctuation.definition.end.bracket.square.go
# ^ source.templ html-template.templ
# ^ source.templ html-template.templ params.html-template.templ punctuation.definition.end.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ punctuation.definition.begin.bracket.curly.go
> @Data{
#^ source.templ html-template.templ block.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ import-expression.templ keyword.control.go
# ^^^^ source.templ html-template.templ block.html-template.templ import-expression.templ
# ^ source.templ html-template.templ block.html-template.templ import-expression.templ punctuation.definition.begin.bracket.curly.go
> message: "You can implement methods on a type.",
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ
> message: "You can implement methods on a type.",
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ
> }.Method("hello") {
#^^^^^^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ
# ^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ start.string-expression.templ
> @test(Data{ message: "You can implement methods on a type." }.Method("hello"))
#^^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.round.go
# ^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.curly.go
# ^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.other.colon.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.end.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.curly.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.other.period.go
# ^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.begin.go
# ^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.end.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.round.go
> <div>
#^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
> { children... }
#^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
> @test(Data{message: "You can implement methods on a type."}.Method("hello"))
#^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.round.go
# ^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.curly.go
# ^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.ellipsis.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.curly.go
> </div>
#^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.arithmetic.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.other.colon.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.end.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.curly.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.other.period.go
# ^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.begin.go
# ^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ string.quoted.double.go punctuation.definition.string.end.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.round.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.round.go
> <div>
#^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
> { children... }
#^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.begin.bracket.curly.go
# ^^^^^^^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.ellipsis.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ punctuation.definition.end.bracket.curly.go
> </div>
#^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.arithmetic.go
# ^^^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ keyword.operator.comparison.go
> }
#^ source.templ html-template.templ block.html-template.templ expression.html-template.templ
# ^ source.templ html-template.templ block.html-template.templ expression.html-template.templ end.string-expression.templ
Expand Down

0 comments on commit 4f85ade

Please sign in to comment.