Skip to content

Commit

Permalink
richer Rust syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Feb 23, 2025
1 parent 631c0f3 commit 87f3b1d
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions data/tree-sitter/queries/rust/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,34 @@

(function_item (identifier) @function)
(function_signature_item (identifier) @function)

"$" @function.macro

(metavariable) @function.macro

(macro_definition
"macro_rules!" @function.macro)

; Attribute macros
(attribute_item
(attribute
(identifier) @function.macro))

(inner_attribute_item
(attribute
(identifier) @function.macro))

(attribute
(scoped_identifier
(identifier) @function.macro .))

; Function-like macros
(macro_invocation
macro: (identifier) @function.macro
"!" @function.macro)
macro: (identifier) @function.macro)

(macro_invocation
macro: (scoped_identifier
(identifier) @function.macro .))

(call_expression
function: (identifier) @function.call)
Expand Down Expand Up @@ -88,6 +113,12 @@
"yield"
] @keyword.return

(type_cast_expression
"as" @keyword.operator)

(qualified_type
"as" @keyword.operator)

[
"default"
"impl"
Expand Down Expand Up @@ -235,6 +266,55 @@
"#"
] @punctuation.special)

(enum_variant
name: (identifier) @constant)

; Assume that uppercase names in paths are types
(scoped_identifier
path: (identifier) @module)

(scoped_identifier
(scoped_identifier
name: (identifier) @module))

(scoped_type_identifier
path: (identifier) @module)

(scoped_type_identifier
path: (identifier) @type
(#match? @type "^[A-Z]"))

(scoped_type_identifier
(scoped_identifier
name: (identifier) @module))

((scoped_identifier
path: (identifier) @type)
(#match? @type "^[A-Z]"))

((scoped_identifier
name: (identifier) @type)
(#match? @type "^[A-Z]"))

((scoped_identifier
name: (identifier) @constant)
(#match? @constant "^[A-Z][A-Z%d_]*$"))

((scoped_identifier
path: (identifier) @type
name: (identifier) @constant)
(#match? @type "^[A-Z]")
(#match? @constant "^[A-Z]"))

((scoped_type_identifier
path: (identifier) @type
name: (type_identifier) @constant)
(#match? @type "^[A-Z]")
(#match? @constant "^[A-Z]"))

((identifier) @constant.builtin
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))

(macro_invocation
macro: (identifier) @function.macro
"!" @function.macro)

0 comments on commit 87f3b1d

Please sign in to comment.