Fix comment highlighting and precedence issues

This commit is contained in:
Michael Netshipise 2026-01-19 07:12:58 +02:00
parent 177b9c811c
commit f1e5e2796f
1 changed files with 113 additions and 165 deletions

View File

@ -1,11 +1,20 @@
; Waltzing Template Highlights ; Waltzing Template Highlights
; Comprehensive query file for tree-sitter-waltzing ; Tree-sitter query file - order matters for precedence
; ====================
; COMMENTS (highest priority - must come first)
; ====================
(template_comment) @comment
(html_comment) @comment
(comment_content) @comment
(html_comment_content) @comment
; ==================== ; ====================
; KEYWORDS ; KEYWORDS
; ==================== ; ====================
; Template keywords (with @ prefix) ; Template keywords
"@use" @keyword.import "@use" @keyword.import
"@import" @keyword.import "@import" @keyword.import
"@struct" @keyword.type "@struct" @keyword.type
@ -18,67 +27,91 @@
"@continue" @keyword.control "@continue" @keyword.control
; Control flow keywords ; Control flow keywords
"else" @keyword.conditional "else" @keyword
"if" @keyword.conditional "if" @keyword
"let" @keyword "let" @keyword
"in" @keyword "in" @keyword
"as" @keyword "as" @keyword
"mut" @keyword "mut" @keyword
"safe" @keyword
; Safe output keyword
"safe" @keyword.function
; ==================== ; ====================
; OPERATORS ; DEFINITIONS
; ==================== ; ====================
(binary_operator) @operator ; Struct definitions
(unary_operator) @operator (struct_definition
(identifier) @type.definition)
(struct_field
(identifier) @property)
; Specific operators ; Enum definitions
"=>" @operator (enum_definition
"=" @operator (identifier) @type.definition)
"!" @operator (enum_variant
"!=" @operator (identifier) @constructor)
"==" @operator
"<" @operator ; Function definitions
"<=" @operator (function_definition
">" @operator (identifier) @function.definition)
">=" @operator (parameter
"<<" @operator (identifier) @variable.parameter)
">>" @operator
"+" @operator
"-" @operator
"*" @operator
"/" @operator
"%" @operator
"&" @operator
"&&" @operator
"|" @operator
"||" @operator
"^" @operator
".." @operator
; ==================== ; ====================
; PUNCTUATION ; FUNCTION TAGS
; ==================== ; ====================
; Brackets (function_path) @function
"{" @punctuation.bracket "<@" @tag.delimiter
"}" @punctuation.bracket "</@" @tag.delimiter
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
; Delimiters ; ====================
"," @punctuation.delimiter ; HTML ELEMENTS
":" @punctuation.delimiter ; ====================
";" @punctuation.delimiter
"." @punctuation.delimiter
; Template expression marker (tag_name) @tag
"@" @punctuation.special (attribute_name) @attribute
(attribute_value) @string
; ====================
; TYPES
; ====================
(primitive_type) @type.builtin
(generic_params
(identifier) @type)
(generic_type
(rust_path) @type)
; ====================
; PATHS AND MODULES
; ====================
(use_statement
(rust_path) @module)
(import_statement
(string_literal) @string.special)
; ====================
; EXPRESSIONS
; ====================
; Template expression @ marker
(simple_expression
"@" @punctuation.special)
(complex_expression
"@" @punctuation.special)
(safe_expression
"@" @punctuation.special)
(attribute_reference
"@" @punctuation.special)
(expression_path
(identifier) @variable)
(field_access
(identifier) @property)
(method_call
(identifier) @function.method)
; ==================== ; ====================
; LITERALS ; LITERALS
@ -89,128 +122,56 @@
(integer_literal) @number (integer_literal) @number
(float_literal) @number (float_literal) @number
(boolean_literal) @constant.builtin (boolean_literal) @constant.builtin
(escape_sequence) @string.escape (escape_sequence) @string.escape
"true" @constant.builtin
"false" @constant.builtin
; ==================== ; ====================
; TYPES ; OPERATORS
; ==================== ; ====================
; Primitive types (binary_operator) @operator
(primitive_type) @type.builtin (unary_operator) @operator
"String" @type.builtin "=>" @operator
"bool" @type.builtin "=" @operator
"char" @type.builtin ".." @operator
"str" @type.builtin
"i8" @type.builtin
"i16" @type.builtin
"i32" @type.builtin
"i64" @type.builtin
"i128" @type.builtin
"u8" @type.builtin
"u16" @type.builtin
"u32" @type.builtin
"u64" @type.builtin
"u128" @type.builtin
"isize" @type.builtin
"usize" @type.builtin
"f32" @type.builtin
"f64" @type.builtin
; Generic type parameters
(generic_params (identifier) @type)
(generic_type (rust_path) @type)
; ==================== ; ====================
; DEFINITIONS ; PUNCTUATION
; ==================== ; ====================
; Struct definitions "{" @punctuation.bracket
(struct_definition (identifier) @type.definition) "}" @punctuation.bracket
(struct_field (identifier) @property.definition) "(" @punctuation.bracket
")" @punctuation.bracket
; Enum definitions "[" @punctuation.bracket
(enum_definition (identifier) @type.definition) "]" @punctuation.bracket
(enum_variant (identifier) @constructor) "," @punctuation.delimiter
":" @punctuation.delimiter
; Function definitions ";" @punctuation.delimiter
(function_definition (identifier) @function.definition) "." @punctuation.delimiter
(parameter (identifier) @variable.parameter)
; ====================
; FUNCTION TAGS (Components)
; ====================
(function_path) @function
(self_closing_function_tag) @tag
(container_function_tag) @tag
; Function tag delimiters
"<@" @tag.delimiter
"</@" @tag.delimiter
"/>" @tag.delimiter
; ====================
; HTML ELEMENTS
; ====================
(tag_name) @tag
(attribute_name) @attribute
(attribute_value) @string
; HTML tag delimiters
"<" @tag.delimiter
">" @tag.delimiter
"</" @tag.delimiter
; ====================
; PATHS AND IDENTIFIERS
; ====================
; Module paths
(rust_path) @module
(use_statement (rust_path) @module)
(import_statement (string_literal) @string.special)
; Expressions
(expression_path (identifier) @variable)
(simple_expression (expression_path) @variable)
(field_access (identifier) @property)
(method_call (identifier) @function.method)
; ==================== ; ====================
; PATTERNS ; PATTERNS
; ==================== ; ====================
(wildcard_pattern) @variable.builtin (wildcard_pattern) @variable.builtin
(identifier_pattern (identifier) @variable) (identifier_pattern
(struct_pattern (rust_path) @type) (identifier) @variable)
(field_pattern (identifier) @property) (struct_pattern
(rust_path) @type)
(field_pattern
(identifier) @property)
; ==================== ; ====================
; COMMENTS ; ATTRIBUTES
; ====================
(template_comment) @comment
(html_comment) @comment
(comment) @comment
; Comment delimiters
"@*" @comment
"*@" @comment
"<!--" @comment
"-->" @comment
; ====================
; ATTRIBUTES (derive, etc.)
; ==================== ; ====================
(attribute_list) @attribute (attribute_list) @attribute
(attribute (identifier) @attribute) (attribute
(identifier) @attribute)
; ==================== ; ====================
; ESCAPE SEQUENCES ; ESCAPE
; ==================== ; ====================
(escape_at) @string.escape (escape_at) @string.escape
@ -222,28 +183,15 @@
(embedded_language) @embedded (embedded_language) @embedded
(language_name) @label (language_name) @label
; Language name keywords
"css" @label
"style" @label
"javascript" @label
"js" @label
"json" @label
"alpine" @label
"html" @label
; Embedded block delimiters
"@```" @punctuation.special
"```@" @punctuation.special
; ==================== ; ====================
; TEXT CONTENT ; TEXT
; ==================== ; ====================
(text_content) @text (text_content) @none
; ==================== ; ====================
; FALLBACK ; FALLBACK (lowest priority - must come last)
; ==================== ; ====================
; Catch-all for identifiers not matched above (rust_path) @module
(identifier) @variable (identifier) @variable