diff options
author | Rose Hudson | 2024-01-02 15:38:13 +0000 |
---|---|---|
committer | GitHub | 2024-01-02 15:38:13 +0000 |
commit | a680b2e409769bf387e5bb7469215b90775e01ba (patch) | |
tree | 4481206838b778a78f4e029074144e2cd5dcc844 /runtime/queries/rust | |
parent | 7fd266efa9b90861f585d0cd7366c94bbeeaa81a (diff) |
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.
Diffstat (limited to 'runtime/queries/rust')
-rw-r--r-- | runtime/queries/rust/highlights.scm | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index 47e57e80..3cda9d52 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -190,6 +190,33 @@ ; 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 ; ------- @@ -203,33 +230,28 @@ (call_expression function: [ - ((identifier) @type.enum.variant - (#match? @type.enum.variant "^[A-Z]")) + ((identifier) @constructor + (#match? @constructor "^[A-Z]")) (scoped_identifier - name: ((identifier) @type.enum.variant - (#match? @type.enum.variant "^[A-Z]"))) + name: ((identifier) @constructor + (#match? @constructor "^[A-Z]"))) ]) ; --- -; Assume that types in match arms are enums and not -; tuple structs. Same for `if let` expressions. +; PascalCase identifiers under a path which is also PascalCase +; are assumed to be constructors if they have methods or fields. ; --- -(match_pattern - (scoped_identifier - name: (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) - ]) +(field_expression + value: (scoped_identifier + path: [ + (identifier) @type + (scoped_identifier + name: (identifier) @type) + ] + name: (identifier) @constructor + (#match? @type "^[A-Z]") + (#match? @constructor "^[A-Z]"))) ; --- ; Other PascalCase identifiers are assumed to be structs. |