Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rust highlights (regression from the reverse-query-precedence PR) #12795

Merged
merged 16 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
209 changes: 108 additions & 101 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,33 +275,6 @@

; 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)

(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]"))

; -------
; Functions
; -------
Expand Down Expand Up @@ -393,6 +302,16 @@
(function_signature_item
name: (identifier) @function)

; ---
; Remaining Paths
nik-rev marked this conversation as resolved.
Show resolved Hide resolved
; ---

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

; -------
; Guess Other Types
; -------
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"))