rust highlights: clean up constructor logic (#8957)
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
This commit is contained in:
parent
7fd266efa9
commit
a680b2e409
1 changed files with 43 additions and 21 deletions
|
@ -189,6 +189,33 @@
|
||||||
|
|
||||||
; TODO: variable.mut to highlight mutable identifiers via locals.scm
|
; 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]"))
|
||||||
|
|
||||||
; -------
|
; -------
|
||||||
; Guess Other Types
|
; Guess Other Types
|
||||||
; -------
|
; -------
|
||||||
|
@ -203,33 +230,28 @@
|
||||||
|
|
||||||
(call_expression
|
(call_expression
|
||||||
function: [
|
function: [
|
||||||
((identifier) @type.enum.variant
|
((identifier) @constructor
|
||||||
(#match? @type.enum.variant "^[A-Z]"))
|
(#match? @constructor "^[A-Z]"))
|
||||||
(scoped_identifier
|
(scoped_identifier
|
||||||
name: ((identifier) @type.enum.variant
|
name: ((identifier) @constructor
|
||||||
(#match? @type.enum.variant "^[A-Z]")))
|
(#match? @constructor "^[A-Z]")))
|
||||||
])
|
])
|
||||||
|
|
||||||
; ---
|
; ---
|
||||||
; Assume that types in match arms are enums and not
|
; PascalCase identifiers under a path which is also PascalCase
|
||||||
; tuple structs. Same for `if let` expressions.
|
; are assumed to be constructors if they have methods or fields.
|
||||||
; ---
|
; ---
|
||||||
|
|
||||||
(match_pattern
|
(field_expression
|
||||||
(scoped_identifier
|
value: (scoped_identifier
|
||||||
name: (identifier) @constructor))
|
path: [
|
||||||
(tuple_struct_pattern
|
(identifier) @type
|
||||||
type: [
|
|
||||||
((identifier) @constructor)
|
|
||||||
(scoped_identifier
|
(scoped_identifier
|
||||||
name: (identifier) @constructor)
|
name: (identifier) @type)
|
||||||
])
|
]
|
||||||
(struct_pattern
|
name: (identifier) @constructor
|
||||||
type: [
|
(#match? @type "^[A-Z]")
|
||||||
((type_identifier) @constructor)
|
(#match? @constructor "^[A-Z]")))
|
||||||
(scoped_type_identifier
|
|
||||||
name: (type_identifier) @constructor)
|
|
||||||
])
|
|
||||||
|
|
||||||
; ---
|
; ---
|
||||||
; Other PascalCase identifiers are assumed to be structs.
|
; Other PascalCase identifiers are assumed to be structs.
|
||||||
|
|
Loading…
Reference in a new issue