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[
 61  "("
 62  ")"
 63  "{"
 64  "}"
 65  "["
 66  "]"
 67] @punctuation.bracket
 68
 69(_
 70  .
 71  "<" @punctuation.bracket
 72  ">" @punctuation.bracket)
 73
 74[
 75  "."
 76  ";"
 77  ","
 78  "::"
 79] @punctuation.delimiter
 80
 81[
 82  "#"
 83] @punctuation.special
 84
 85[
 86  "as"
 87  "async"
 88  "await"
 89  "const"
 90  "default"
 91  "dyn"
 92  "enum"
 93  "extern"
 94  "fn"
 95  "impl"
 96  "let"
 97  "macro_rules!"
 98  "mod"
 99  "move"
100  "pub"
101  "raw"
102  "ref"
103  "static"
104  "struct"
105  "trait"
106  "type"
107  "union"
108  "unsafe"
109  "use"
110  "where"
111  (crate)
112  (mutable_specifier)
113  (super)
114] @keyword
115
116[
117  "break"
118  "continue"
119  "else"
120  "for"
121  "if"
122  "in"
123  "loop"
124  "match"
125  "return"
126  "while"
127  "yield"
128] @keyword.control
129
130[
131  (string_literal)
132  (raw_string_literal)
133  (char_literal)
134] @string
135
136(escape_sequence) @string.escape
137
138[
139  (integer_literal)
140  (float_literal)
141] @number
142
143(boolean_literal) @boolean
144
145[
146  (line_comment)
147  (block_comment)
148] @comment
149
150[
151  (line_comment (doc_comment))
152  (block_comment (doc_comment))
153] @comment.doc
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  ">>"
184  ">>="
185  "@"
186  "^"
187  "^="
188  "|"
189  "|="
190  "||"
191  "?"
192] @operator
193
194; Avoid highlighting these as operators when used in doc comments.
195(unary_expression "!" @operator)
196operator: "/" @operator
197
198(lifetime) @lifetime
199
200(parameter (identifier) @variable.parameter)
201
202(attribute_item (attribute [
203  (identifier) @attribute
204  (scoped_identifier name: (identifier) @attribute)
205  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
206  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
207]))
208
209(inner_attribute_item (attribute [
210  (identifier) @attribute
211  (scoped_identifier name: (identifier) @attribute)
212  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
213  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
214]))