Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/sway/highlights.scm')
| -rw-r--r-- | runtime/queries/sway/highlights.scm | 214 |
1 files changed, 116 insertions, 98 deletions
diff --git a/runtime/queries/sway/highlights.scm b/runtime/queries/sway/highlights.scm index 969ef776..98f4d449 100644 --- a/runtime/queries/sway/highlights.scm +++ b/runtime/queries/sway/highlights.scm @@ -1,87 +1,14 @@ ; ------- -; Basic identifiers +; Tree-Sitter doesn't allow overrides in regards to captures, +; though it is possible to affect the child node of a captured +; node. Thus, the approach here is to flip the order so that +; overrides are unnecessary. ; ------- -; We do not style ? as an operator on purpose as it allows styling ? differently, as many highlighters do. @operator.special might have been a better scope, but @special is already documented so the change would break themes (including the intent of the default theme) -"?" @special - -(type_identifier) @type -(identifier) @variable -(field_identifier) @variable.other.member - ; ------- -; Operators +; Types ; ------- -[ - "*" - "'" - "->" - "=>" - "<=" - "=" - "==" - "!" - "!=" - "%" - "%=" - "&" - "&=" - "&&" - "|" - "|=" - "||" - "^" - "^=" - "*" - "*=" - "-" - "-=" - "+" - "+=" - "/" - "/=" - ">" - "<" - ">=" - ">>" - "<<" - ">>=" - "<<=" - "@" - ".." - "..=" - "'" -] @operator - -; ------- -; Paths -; ------- - -(use_declaration - argument: (identifier) @namespace) -(use_wildcard - (identifier) @namespace) -(dep_item - name: (identifier) @namespace) -(scoped_use_list - path: (identifier)? @namespace) -(use_list - (identifier) @namespace) -(use_as_clause - path: (identifier)? @namespace - alias: (identifier) @namespace) - -; --- -; Remaining Paths -; --- - -(scoped_identifier - path: (identifier)? @namespace - name: (identifier) @namespace) -(scoped_type_identifier - path: (identifier) @namespace) - ; --- ; Primitives ; --- @@ -252,10 +179,6 @@ ; ------- ; Guess Other Types ; ------- -; Other PascalCase identifiers are assumed to be structs. - -((identifier) @type - (#match? @type "^[A-Z]")) ((identifier) @constant (#match? @constant "^[A-Z][A-Z\\d_]*$")) @@ -267,28 +190,40 @@ (call_expression function: [ - ((identifier) @constructor - (#match? @constructor "^[A-Z]")) + ((identifier) @type.enum.variant + (#match? @type.enum.variant "^[A-Z]")) (scoped_identifier - name: ((identifier) @constructor - (#match? @constructor "^[A-Z]"))) + name: ((identifier) @type.enum.variant + (#match? @type.enum.variant "^[A-Z]"))) ]) ; --- -; PascalCase identifiers under a path which is also PascalCase -; are assumed to be constructors if they have methods or fields. +; Assume that types in match arms are enums and not +; tuple structs. Same for `if let` expressions. +; --- + +(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) + ]) + +; --- +; Other PascalCase identifiers are assumed to be structs. ; --- -(field_expression - value: (scoped_identifier - path: [ - (identifier) @type - (scoped_identifier - name: (identifier) @type) - ] - name: (identifier) @constructor - (#match? @type "^[A-Z]") - (#match? @constructor "^[A-Z]"))) +((identifier) @type + (#match? @type "^[A-Z]")) ; ------- ; Functions @@ -316,3 +251,86 @@ (function_signature_item name: (identifier) @function) + +; ------- +; Operators +; ------- + +[ + "*" + "'" + "->" + "=>" + "<=" + "=" + "==" + "!" + "!=" + "%" + "%=" + "&" + "&=" + "&&" + "|" + "|=" + "||" + "^" + "^=" + "*" + "*=" + "-" + "-=" + "+" + "+=" + "/" + "/=" + ">" + "<" + ">=" + ">>" + "<<" + ">>=" + "<<=" + "@" + ".." + "..=" + "'" +] @operator + +; ------- +; Paths +; ------- + +(use_declaration + argument: (identifier) @namespace) +(use_wildcard + (identifier) @namespace) +(dep_item + name: (identifier) @namespace) +(scoped_use_list + path: (identifier)? @namespace) +(use_list + (identifier) @namespace) +(use_as_clause + path: (identifier)? @namespace + alias: (identifier) @namespace) + +; --- +; Remaining Paths +; --- + +(scoped_identifier + path: (identifier)? @namespace + name: (identifier) @namespace) +(scoped_type_identifier + path: (identifier) @namespace) + +; ------- +; Remaining Identifiers +; ------- + +"?" @special + +(type_identifier) @type +(identifier) @variable +(field_identifier) @variable.other.member |