highlights.scm

  1(identifier) @variable
  2(metavariable) @variable
  3(type_identifier) @type
  4(fragment_specifier) @type
  5(primitive_type) @type.builtin
  6(self) @variable.special
  7(field_identifier) @property
  8(shorthand_field_identifier) @property
  9
 10(trait_item name: (type_identifier) @type.interface)
 11(impl_item trait: (type_identifier) @type.interface)
 12(abstract_type trait: (type_identifier) @type.interface)
 13(dynamic_type trait: (type_identifier) @type.interface)
 14(trait_bounds (type_identifier) @type.interface)
 15
 16(call_expression
 17  function: [
 18    (identifier) @function
 19    (scoped_identifier
 20      name: (identifier) @function)
 21    (field_expression
 22      field: (field_identifier) @function.method)
 23  ])
 24
 25(generic_function
 26  function: [
 27    (identifier) @function
 28    (scoped_identifier
 29      name: (identifier) @function)
 30    (field_expression
 31      field: (field_identifier) @function.method)
 32  ])
 33
 34(function_item name: (identifier) @function.definition)
 35(function_signature_item name: (identifier) @function.definition)
 36
 37(macro_invocation
 38  macro: [
 39    (identifier) @function.special
 40    (scoped_identifier
 41      name: (identifier) @function.special)
 42  ])
 43
 44(macro_invocation
 45  "!" @function.special)
 46
 47(macro_definition
 48  name: (identifier) @function.special.definition)
 49
 50; Identifier conventions
 51
 52; Assume uppercase names are types/enum-constructors
 53((identifier) @type
 54 (#match? @type "^[A-Z]"))
 55
 56; Assume all-caps names are constants
 57((identifier) @constant
 58 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 59
 60; Ensure enum variants are highlighted correctly regardless of naming convention
 61(enum_variant name: (identifier) @type)
 62
 63[
 64  "("
 65  ")"
 66  "{"
 67  "}"
 68  "["
 69  "]"
 70] @punctuation.bracket
 71
 72(_
 73  .
 74  "<" @punctuation.bracket
 75  ">" @punctuation.bracket)
 76
 77[
 78  "."
 79  ";"
 80  ","
 81  "::"
 82] @punctuation.delimiter
 83
 84[
 85  "#"
 86] @punctuation.special
 87
 88[
 89  "as"
 90  "async"
 91  "const"
 92  "default"
 93  "dyn"
 94  "enum"
 95  "extern"
 96  "fn"
 97  "impl"
 98  "let"
 99  "macro_rules!"
100  "mod"
101  "move"
102  "pub"
103  "raw"
104  "ref"
105  "static"
106  "struct"
107  "for"
108  "trait"
109  "type"
110  "union"
111  "unsafe"
112  "use"
113  "where"
114  (crate)
115  (mutable_specifier)
116  (super)
117] @keyword
118
119[
120  "await"
121  "break"
122  "continue"
123  "else"
124  "if"
125  "in"
126  "loop"
127  "match"
128  "return"
129  "while"
130  "yield"
131] @keyword.control
132
133(for_expression
134  ("for" @keyword.control))
135
136[
137  (string_literal)
138  (raw_string_literal)
139  (char_literal)
140] @string
141
142(escape_sequence) @string.escape
143
144[
145  (integer_literal)
146  (float_literal)
147] @number
148
149(boolean_literal) @boolean
150
151[
152  (line_comment)
153  (block_comment)
154] @comment
155
156[
157  (line_comment (doc_comment))
158  (block_comment (doc_comment))
159] @comment.doc
160
161[
162  "!="
163  "%"
164  "%="
165  "&"
166  "&="
167  "&&"
168  "*"
169  "*="
170  "+"
171  "+="
172  "-"
173  "-="
174  "->"
175  ".."
176  "..="
177  "..."
178  "/="
179  ":"
180  "<<"
181  "<<="
182  "<"
183  "<="
184  "="
185  "=="
186  "=>"
187  ">"
188  ">="
189  ">>"
190  ">>="
191  "@"
192  "^"
193  "^="
194  "|"
195  "|="
196  "||"
197  "?"
198] @operator
199
200; Avoid highlighting these as operators when used in doc comments.
201(unary_expression "!" @operator)
202operator: "/" @operator
203
204(lifetime
205  "'" @lifetime
206  (identifier) @lifetime)
207
208(parameter (identifier) @variable.parameter)
209
210(attribute_item (attribute [
211  (identifier) @attribute
212  (scoped_identifier name: (identifier) @attribute)
213  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
214  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
215]))
216
217(inner_attribute_item (attribute [
218  (identifier) @attribute
219  (scoped_identifier name: (identifier) @attribute)
220  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
221  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
222]))