highlights.scm

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