Skip to content

Commit

Permalink
queries: update with the latest files from nvim-treesitter
Browse files Browse the repository at this point in the history
Forgot to update the files after tree-sitter-templ was included in
nvim-treesitter
  • Loading branch information
vrischmann committed Jan 22, 2024
1 parent d7d19f1 commit f9c60b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 81 deletions.
100 changes: 22 additions & 78 deletions queries/templ/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,105 +1,49 @@
; TODO(vincent): can we use injection ? I can't get it working

; A bunch of these are taken from:
; * https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/go/highlights.scm
; * https://github.com/tree-sitter/tree-sitter-go/blob/master/queries/highlights.scm

(package_identifier) @namespace

(parameter_declaration (identifier) @parameter)
(variadic_parameter_declaration (identifier) @parameter)

(function_declaration
name: (identifier) @function)

(type_spec name: (type_identifier) @type.definition)
(type_identifier) @type
(field_identifier) @property
(identifier) @variable

; Function calls

(call_expression
function: (identifier) @function.call)

(call_expression
function: (selector_expression
field: (field_identifier) @method.call))

;
; These are Templ specific
;

; inherits: go
(component_declaration
name: (component_identifier) @function)

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

(attribute
name: (attribute_name) @tag.attribute)

(attribute
value: (quoted_attribute_value) @string)

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

(css_identifier) @function

(css_property
name: (css_property_name) @attribute)
name: (css_property_name) @property)

(css_property
value: (css_property_value) @string)

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

(component_import
name: (component_identifier) @function)

(component_render) @function.call

[
"@"
] @operator
(element_comment) @comment @spell

"@" @operator

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

[
"import"
"package"
] @include

[
"else"
"case"
"switch"
"if"
"default"
] @conditional

"for" @repeat

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

; Comments

(comment) @comment @spell

(element_comment) @comment @spell
14 changes: 11 additions & 3 deletions queries/templ/injections.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
((script_block_text) @injection.content (#set! injection.language "javascript"))
((script_element_text) @injection.content (#set! injection.language "javascript"))
; inherits: go
((element_comment) @injection.content
(#set! injection.language "comment"))

((style_element_text) @injection.content (#set! injection.language "css"))
((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"))

0 comments on commit f9c60b5

Please sign in to comment.