Skip to content

Commit

Permalink
fix: Rust highlights (regression from the reverse-query-precedence PR) (
Browse files Browse the repository at this point in the history
#12795)

Co-authored-by: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com>
  • Loading branch information
nik-rev and nik-rev authored Feb 7, 2025
1 parent c36ed6a commit 1b89f99
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 101 deletions.
2 changes: 0 additions & 2 deletions runtime/queries/haskell/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@
)


(con_unit) @constant.builtin ; unit, as in ()

(comment) @comment


Expand Down
205 changes: 106 additions & 99 deletions runtime/queries/rust/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@
path: (identifier)? @namespace
alias: (identifier) @namespace)

; ---
; Remaining Paths
; ---

(scoped_identifier
path: (identifier)? @namespace
name: (identifier) @namespace)
(scoped_type_identifier
path: (identifier) @namespace)

; -------
; Types
; -------
Expand All @@ -97,6 +87,8 @@
name: (type_identifier) @type.parameter)
((type_arguments (type_identifier) @constant)
(#match? @constant "^[A-Z_]+$"))
(type_arguments (type_identifier) @type)
(tuple_struct_pattern "_" @comment.unused)
((type_arguments (type_identifier) @comment.unused)
(#eq? @comment.unused "_"))

Expand Down Expand Up @@ -126,7 +118,6 @@
; ---

(self) @variable.builtin
(enum_variant (identifier) @type.enum.variant)

(field_initializer
(field_identifier) @variable.other.member)
Expand All @@ -141,63 +132,6 @@
"'" @label
(identifier) @label)

; ---
; Prelude
; ---

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


(call_expression
(identifier) @function.builtin
(#any-of? @function.builtin
"drop"
"size_of"
"size_of_val"
"align_of"
"align_of_val"))

((type_identifier) @type.builtin
(#any-of?
@type.builtin
"Send"
"Sized"
"Sync"
"Unpin"
"Drop"
"Fn"
"FnMut"
"FnOnce"
"AsMut"
"AsRef"
"From"
"Into"
"DoubleEndedIterator"
"ExactSizeIterator"
"Extend"
"IntoIterator"
"Iterator"
"Option"
"Result"
"Clone"
"Copy"
"Debug"
"Default"
"Eq"
"Hash"
"Ord"
"PartialEq"
"PartialOrd"
"ToOwned"
"Box"
"String"
"ToString"
"Vec"
"FromIterator"
"TryFrom"
"TryInto"))

; ---
; Punctuation
; ---
Expand Down Expand Up @@ -229,8 +163,10 @@
"<"
">"
] @punctuation.bracket)
(for_lifetimes ["<" ">"] @punctuation.bracket)
(closure_parameters
"|" @punctuation.bracket)
(bracketed_type ["<" ">"] @punctuation.bracket)

; ---
; Variables
Expand Down Expand Up @@ -339,32 +275,15 @@

; TODO: variable.mut to highlight mutable identifiers via locals.scm

; -------
; Constructors
; -------
; TODO: this is largely guesswork, remove it once we get actual info from locals.scm or r-a

(struct_expression
name: (type_identifier) @constructor)
; ---
; Remaining Paths
; ---

(tuple_struct_pattern
type: [
(identifier) @constructor
(scoped_identifier
name: (identifier) @constructor)
])
(struct_pattern
type: [
((type_identifier) @constructor)
(scoped_type_identifier
name: (type_identifier) @constructor)
])
(match_pattern
((identifier) @constructor) (#match? @constructor "^[A-Z]"))
(or_pattern
((identifier) @constructor)
((identifier) @constructor)
(#match? @constructor "^[A-Z]"))
(scoped_identifier
path: (identifier)? @namespace
name: (identifier) @namespace)
(scoped_type_identifier
path: (identifier) @namespace)

; -------
; Functions
Expand Down Expand Up @@ -436,18 +355,43 @@
(#match? @type "^[A-Z]")
(#match? @constructor "^[A-Z]")))

(enum_variant (identifier) @type.enum.variant)


; -------
; Constructors
; -------
; TODO: this is largely guesswork, remove it once we get actual info from locals.scm or r-a

(struct_expression
name: (type_identifier) @constructor)

(tuple_struct_pattern
type: [
(identifier) @constructor
(scoped_identifier
name: (identifier) @constructor)
])
(struct_pattern
type: [
((type_identifier) @constructor)
(scoped_type_identifier
name: (type_identifier) @constructor)
])
(match_pattern
((identifier) @constructor) (#match? @constructor "^[A-Z]"))
(or_pattern
((identifier) @constructor)
((identifier) @constructor)
(#match? @constructor "^[A-Z]"))

; ---
; Macros
; ---

(attribute
(identifier) @special
arguments: (token_tree (identifier) @type)
(#eq? @special "derive")
)

(attribute
(identifier) @function.macro)
(inner_attribute_item "!" @punctuation)
(attribute
[
(identifier) @function.macro
Expand All @@ -470,3 +414,66 @@

(metavariable) @variable.parameter
(fragment_specifier) @type

(attribute
(identifier) @special
arguments: (token_tree (identifier) @type)
(#eq? @special "derive")
)

; ---
; Prelude
; ---

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


(call_expression
(identifier) @function.builtin
(#any-of? @function.builtin
"drop"
"size_of"
"size_of_val"
"align_of"
"align_of_val"))

((type_identifier) @type.builtin
(#any-of?
@type.builtin
"Send"
"Sized"
"Sync"
"Unpin"
"Drop"
"Fn"
"FnMut"
"FnOnce"
"AsMut"
"AsRef"
"From"
"Into"
"DoubleEndedIterator"
"ExactSizeIterator"
"Extend"
"IntoIterator"
"Iterator"
"Option"
"Result"
"Clone"
"Copy"
"Debug"
"Default"
"Eq"
"Hash"
"Ord"
"PartialEq"
"PartialOrd"
"ToOwned"
"Box"
"String"
"ToString"
"Vec"
"FromIterator"
"TryFrom"
"TryInto"))

0 comments on commit 1b89f99

Please sign in to comment.