Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

languages: add templ #8540

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
| t32 | ✓ | | | |
| tablegen | ✓ | ✓ | ✓ | |
| task | ✓ | | | |
| templ | ✓ | | | `templ` |
| tfvars | ✓ | | ✓ | `terraform-ls` |
| todotxt | ✓ | | | |
| toml | ✓ | | | `taplo` |
Expand Down
14 changes: 14 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ svlangserver = { command = "svlangserver", args = [] }
swipl = { command = "swipl", args = [ "-g", "use_module(library(lsp_server))", "-g", "lsp_server:main", "-t", "halt", "--", "stdio" ] }
tailwindcss-ls = { command = "tailwindcss-language-server", args = ["--stdio"] }
taplo = { command = "taplo", args = ["lsp", "stdio"] }
templ = { command = "templ", args = ["lsp"] }
terraform-ls = { command = "terraform-ls", args = ["serve"] }
texlab = { command = "texlab" }
vala-language-server = { command = "vala-language-server" }
Expand Down Expand Up @@ -2998,3 +2999,16 @@ roots = []
[[grammar]]
name = "gemini"
source = { git = "https://git.sr.ht/~sfr/tree-sitter-gemini", rev = "3cc5e4bdf572d5df4277fc2e54d6299bd59a54b3" }

[[language]]
name = "templ"
scope = "source.templ"
file-types = ["templ"]
roots = ["go.work", "go.mod"]
comment-token = "//"
indent = { tab-width = 2, unit = " " }
language-servers = [ "templ" ]

[[grammar]]
name = "templ"
source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "ea56ac0655243490a4929a988f4eaa91dfccc995" }
99 changes: 99 additions & 0 deletions runtime/queries/templ/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
(package_identifier) @namespace

(parameter_declaration (identifier) @variable.parameter)
(variadic_parameter_declaration (identifier) @variable.parameter)

(function_declaration
name: (identifier) @function)

(type_spec name: (type_identifier) @type)
(type_identifier) @type
(field_identifier) @variable.other.member
(identifier) @variable

; Function calls

(call_expression
function: (identifier) @function)

(call_expression
function: (selector_expression
field: (field_identifier) @function))

;
; These are Templ specific
;

(component_declaration
name: (component_identifier) @function)

(tag_start) @tag
(tag_end) @tag
(self_closing_tag) @tag
(style_element) @tag

(attribute
name: (attribute_name) @attribute)
(attribute
value: (quoted_attribute_value) @string)

(element_text) @string.special
(style_element_text) @string.special

(css_property
name: (css_property_name) @attribute)

(expression) @function.method
(dynamic_class_attribute_value) @function.method

(component_import
name: (component_identifier) @function)

(component_render) @function

[
"@"
] @operator

[
"func"
"var"
"const"
"templ"
"css"
"type"
"struct"
"range"
"script"
] @keyword.storage.type

[
"return"
] @keyword.control.return

[
"import"
"package"
] @keyword.control.import

[
"else"
"case"
"switch"
"if"
"default"
] @keyword.control.conditional

"for" @keyword.control.repeat

[
(interpreted_string_literal)
(raw_string_literal)
(rune_literal)
] @string

; Comments

(comment) @comment

(element_comment) @comment
4 changes: 4 additions & 0 deletions runtime/queries/templ/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((script_block_text) @injection.content (#set! injection.language "javascript"))
((script_element_text) @injection.content (#set! injection.language "javascript"))

((style_element_text) @injection.content (#set! injection.language "css"))
Loading