highlights.scm

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