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
  9(shorthand_field_initializer
 10  (identifier) @property)
 11
 12(trait_item name: (type_identifier) @type.interface)
 13(impl_item trait: (type_identifier) @type.interface)
 14(abstract_type trait: (type_identifier) @type.interface)
 15(dynamic_type trait: (type_identifier) @type.interface)
 16(trait_bounds (type_identifier) @type.interface)
 17
 18(call_expression
 19  function: [
 20    (identifier) @function
 21    (scoped_identifier
 22      name: (identifier) @function)
 23    (field_expression
 24      field: (field_identifier) @function.method)
 25  ])
 26
 27(generic_function
 28  function: [
 29    (identifier) @function
 30    (scoped_identifier
 31      name: (identifier) @function)
 32    (field_expression
 33      field: (field_identifier) @function.method)
 34  ])
 35
 36(function_item name: (identifier) @function.definition)
 37(function_signature_item name: (identifier) @function.definition)
 38
 39(macro_invocation
 40  macro: [
 41    (identifier) @function.special
 42    (scoped_identifier
 43      name: (identifier) @function.special)
 44  ]
 45  "!" @function.special)
 46
 47(macro_definition
 48  name: (identifier) @function.special.definition)
 49
 50(mod_item
 51  name: (identifier) @module)
 52
 53(visibility_modifier [
 54  (crate) @keyword
 55  (super) @keyword
 56])
 57
 58; Identifier conventions
 59
 60; Assume uppercase names are types/enum-constructors
 61((identifier) @type
 62 (#match? @type "^[A-Z]"))
 63
 64; Assume all-caps names are constants
 65((identifier) @constant
 66 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 67
 68[
 69  "("
 70  ")"
 71  "{"
 72  "}"
 73  "["
 74  "]"
 75] @punctuation.bracket
 76
 77(_
 78  .
 79  "<" @punctuation.bracket
 80  ">" @punctuation.bracket)
 81
 82[
 83  "."
 84  ";"
 85  ","
 86  "::"
 87] @punctuation.delimiter
 88
 89[
 90  "#"
 91] @punctuation.special
 92
 93[
 94  "as"
 95  "async"
 96  "await"
 97  "break"
 98  "const"
 99  "continue"
100  "default"
101  "dyn"
102  "else"
103  "enum"
104  "extern"
105  "fn"
106  "for"
107  "if"
108  "impl"
109  "in"
110  "let"
111  "loop"
112  "macro_rules!"
113  "match"
114  "mod"
115  "move"
116  "pub"
117  "raw"
118  "ref"
119  "return"
120  "static"
121  "struct"
122  "trait"
123  "type"
124  "union"
125  "unsafe"
126  "use"
127  "where"
128  "while"
129  "yield"
130  (mutable_specifier)
131] @keyword
132
133[
134  (string_literal)
135  (raw_string_literal)
136  (char_literal)
137] @string
138
139(escape_sequence) @string.escape
140
141[
142  (integer_literal)
143  (float_literal)
144] @number
145
146(boolean_literal) @boolean
147
148[
149  (line_comment)
150  (block_comment)
151] @comment
152
153[
154  (line_comment (doc_comment))
155  (block_comment (doc_comment))
156] @comment.doc
157
158[
159  "!="
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] @operator
196
197; Avoid highlighting these as operators when used in doc comments.
198(unary_expression "!" @operator)
199operator: "/" @operator
200
201(lifetime) @lifetime
202(lifetime (identifier) @lifetime)
203
204(parameter (identifier) @variable.parameter)
205
206(attribute_item (attribute [
207  (identifier) @attribute
208  (scoped_identifier name: (identifier) @attribute)
209]))
210(inner_attribute_item (attribute [
211  (identifier) @attribute
212  (scoped_identifier name: (identifier) @attribute)
213]))
214; Match nested snake case identifiers in attribute items.
215(token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
216; Override the attribute match for paths in scoped type/enum identifiers.
217(token_tree (identifier) @variable "::" (identifier) @type (#match? @type "^[A-Z]"))