diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 6dc1b89f..0b784edf 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -289,7 +289,7 @@ | task | ✓ | | | | | | | tcl | ✓ | | ✓ | | | | | teal | ✓ | | | | | `teal-language-server` | -| templ | ✓ | | | | | `templ` | +| templ | ✓ | ✓ | | ✓ | ✓ | `templ` | | tera | ✓ | | | | | | | textproto | ✓ | ✓ | ✓ | | | | | tfvars | ✓ | | ✓ | | | `terraform-ls` | diff --git a/languages.toml b/languages.toml index 5debe86c..b0b6a7b4 100644 --- a/languages.toml +++ b/languages.toml @@ -4138,7 +4138,7 @@ language-servers = [ "templ" ] [[grammar]] name = "templ" -source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "47594c5cbef941e6a3ccf4ddb934a68cf4c68075" } +source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "68d6707ed20159ae7525241b8161c126dc1c620c" } [[language]] name = "dbml" diff --git a/runtime/queries/templ/highlights.scm b/runtime/queries/templ/highlights.scm index d015970c..f91d3ad4 100644 --- a/runtime/queries/templ/highlights.scm +++ b/runtime/queries/templ/highlights.scm @@ -4,55 +4,98 @@ name: (css_identifier) @function) (script_declaration name: (script_identifier) @function) - (component_declaration name: (component_identifier) @function) -(tag_start) @tag -(tag_end) @tag -(self_closing_tag) @tag -(style_element) @tag +; Elements + +(tag_start name: (_) @tag) +(tag_end name: (_) @tag) +(self_closing_tag name: (_) @tag) + +(tag_start ["<" ">"] @punctuation.bracket) +(tag_end [""] @punctuation.bracket) +(self_closing_tag ["<" "/>"] @punctuation.bracket) + +(style_tag_start "style" @tag) +(style_tag_end "style" @tag) +(self_closing_style_tag "style" @tag) + +(style_tag_start ["<" ">"] @punctuation.bracket) +(style_tag_end [""] @punctuation.bracket) +(self_closing_style_tag ["<" "/>"] @punctuation.bracket) + +(script_tag_start "script" @tag) +(script_tag_end "script" @tag) +(self_closing_script_tag "script" @tag) + +(script_tag_start ["<" ">"] @punctuation.bracket) +(script_tag_end [""] @punctuation.bracket) +(self_closing_script_tag ["<" "/>"] @punctuation.bracket) + +; Attributes (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) + name: (css_property_name) @variable.other.member) (css_property value: (css_property_value) @constant) -(expression) @function.method (dynamic_class_attribute_value) @function.method +; Special Elements and Attributes + +((attribute + name: (attribute_name) @attribute + value: (quoted_attribute_value (attribute_value) @markup.link.url)) + (#any-of? @attribute "href" "src")) + +((element + (tag_start + name: (_) @tag) + (element_text) @markup.link.label) + (#eq? @tag "a")) + +((element + (tag_start + name: (_) @tag) + (element_text) @markup.bold) + (#any-of? @tag "strong" "b")) + +((element + (tag_start + name: (_) @tag) + (element_text) @markup.italic) + (#any-of? @tag "em" "i")) + +((element + (tag_start + name: (_) @tag) + (element_text) @markup.strikethrough) + (#any-of? @tag "s" "del")) + +; Extra Features + (component_import name: (component_identifier) @function) (component_render) @function -[ - "@" -] @operator +"@" @operator [ "templ" "css" "type" - "script" ] @keyword.storage.type +(script_declaration "script" @keyword.storage.type) -[ - (interpreted_string_literal) - (raw_string_literal) - (rune_literal) -] @string +["{{" "}}"] @punctuation.bracket ; Comments -(comment) @comment - (element_comment) @comment diff --git a/runtime/queries/templ/injections.scm b/runtime/queries/templ/injections.scm index 4dd5a630..b9cf5a06 100644 --- a/runtime/queries/templ/injections.scm +++ b/runtime/queries/templ/injections.scm @@ -1,4 +1,13 @@ -((script_block_text) @injection.content (#set! injection.language "javascript")) -((script_element_text) @injection.content (#set! injection.language "javascript")) +; inherits: go -((style_element_text) @injection.content (#set! injection.language "css")) +((element_comment) @injection.content + (#set! injection.language "comment")) + +((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")) diff --git a/runtime/queries/templ/rainbows.scm b/runtime/queries/templ/rainbows.scm new file mode 100644 index 00000000..b0f3ecd6 --- /dev/null +++ b/runtime/queries/templ/rainbows.scm @@ -0,0 +1,38 @@ +; inherits: go + +[ + (expression) + (component_switch_statement) + (component_render) + (component_children_expression) + (doctype) + (spread_attributes) + (conditional_attribute_block) + (css_declaration) + (dynamic_class_attribute_value) + (component_block) + (script_block) + (rawgo_block) + (literal_value) +] @rainbow.scope + +[ + "{" + "}" + "{!" + "}" + "{{" + "}}" + "<" + ">" + "" + "