on master help sign in
Rewritten Rust `highlights.scm` (#425)
084a8a9Kirawi
book/src/themes.md+1
@@ -51,6 +51,7 @@ Possible keys:
51| `attribute` | |
51| `attribute` | |
52| `keyword` | |
52| `keyword` | |
53| `keyword.directive` | Preprocessor directives (\#if in C) |
53| `keyword.directive` | Preprocessor directives (\#if in C) |
54+| `keyword.control` | Control flow |
54| `namespace` | |
55| `namespace` | |
55| `punctuation` | |
56| `punctuation` | |
56| `punctuation.delimiter` | |
57| `punctuation.delimiter` | |
helix-core/src/syntax.rs+2−2
@@ -161,7 +161,7 @@ impl LanguageConfiguration {
161
161
162 let injections_query = read_query(&language, "injections.scm");
162 let injections_query = read_query(&language, "injections.scm");
163
163
164− let locals_query = "";
164+ let locals_query = read_query(&language, "locals.scm");
165
165
166 if highlights_query.is_empty() {
166 if highlights_query.is_empty() {
167 None
167 None
@@ -171,7 +171,7 @@ impl LanguageConfiguration {
171 language,
171 language,
172 &highlights_query,
172 &highlights_query,
173 &injections_query,
173 &injections_query,
174− locals_query,
174+ &locals_query,
175 )
175 )
176 .unwrap(); // TODO: no unwrap
176 .unwrap(); // TODO: no unwrap
177 config.configure(scopes);
177 config.configure(scopes);
runtime/queries/rust/highlights.scm+303−181
@@ -1,214 +1,336 @@
1−; Identifier conventions
1+; -------
2+; Tree-Sitter doesn't allow overrides in regards to captures,
3+; though it is possible to affect the child node of a captured
4+; node. Thus, the approach here is to flip the order so that
5+; overrides are unnecessary.
6+; -------
2
7
3
8
4−; Assume all-caps names are constants
5−((identifier) @constant
6− (#match? @constant "^[A-Z][A-Z\\d_]+$"))
7
9
8−; Assume other uppercase names are enum constructors
10+; -------
9−(enum_variant) @type.enum.variant
11+; Types
10−((identifier) @constructor
12+; -------
11− (#match? @constructor "^[A-Z]"))
12
13
13−; Assume that uppercase names in paths are types
14+; ---
14−(mod_item
15+; Primitives
15− name: (identifier) @namespace)
16+; ---
16−(scoped_identifier
17− path: (identifier) @namespace)
18−(scoped_identifier
19− (scoped_identifier
20− name: (identifier) @namespace))
21−(scoped_type_identifier
22− path: (identifier) @namespace)
23−(scoped_type_identifier
24− (scoped_identifier
25− name: (identifier) @namespace))
26
17
27−((scoped_identifier
18+(escape_sequence) @escape
28− path: (identifier) @type)
19+(primitive_type) @type.builtin
29− (#match? @type "^[A-Z]"))
20+(boolean_literal) @constant.builtin
30−((scoped_identifier
21+[
31− path: (scoped_identifier
22+ (integer_literal)
32− name: (identifier) @type))
23+ (float_literal)
33− (#match? @type "^[A-Z]"))
24+] @number
25+[
26+ (char_literal)
27+ (string_literal)
28+ (raw_string_literal)
29+] @string
30+[
31+ (line_comment)
32+ (block_comment)
33+] @comment
34
34
35−; Namespaces
35+; ---
36+; Extraneous
37+; ---
36
38
37−(crate) @namespace
39+(self) @variable.builtin
38−(extern_crate_declaration
40+(enum_variant (identifier) @type.enum.variant)
39− (crate)
40− name: (identifier) @namespace)
41−(scoped_use_list
42− path: (identifier) @namespace)
43−(scoped_use_list
44− path: (scoped_identifier
45− (identifier) @namespace))
46−(use_list (scoped_identifier (identifier) @namespace . (_)))
47
41
48−; Function calls
42+(field_initializer
43+ (field_identifier) @property)
44+(shorthand_field_initializer) @variable
45+(shorthand_field_identifier) @variable
49
46
50−(call_expression
47+(lifetime
51− function: (identifier) @function)
48+ "'" @label
52−(call_expression
49+ (identifier) @label)
53− function: (field_expression
50+(loop_label
54− field: (field_identifier) @function.method))
55−(call_expression
56− function: (scoped_identifier
57− "::"
58− name: (identifier) @function))
51+ (identifier) @type)
59
52
60−(generic_function
53+; ---
61− function: (identifier) @function)
54+; Punctuation
62−(generic_function
55+; ---
63− function: (scoped_identifier
64− name: (identifier) @function))
65−(generic_function
66− function: (field_expression
67− field: (field_identifier) @function.method))
68
56
69−(macro_invocation
57+[
70− macro: (identifier) @function.macro
58+ "::"
71− "!" @function.macro)
59+ "."
72−(macro_invocation
60+ ";"
73− macro: (scoped_identifier
61+] @punctuation.delimiter
74− (identifier) @function.macro .))
75
62
76−; (metavariable) @variable
63+[
77−(metavariable) @function.macro
64+ "("
65+ ")"
66+ "["
67+ "]"
68+] @punctuation.bracket
69+(type_arguments
70+ [
71+ "<"
72+ ">"
73+ ] @punctuation.bracket)
74+(type_parameters
75+ [
76+ "<"
77+ ">"
78+ ] @punctuation.bracket)
78
79
79−"$" @function.macro
80+; ---
81+; Parameters
82+; ---
80
83
81−; Function definitions
84+(parameter
85+ pattern: (identifier) @variable.parameter)
86+(closure_parameters
87+ (identifier) @variable.parameter)
82
88
83−(function_item (identifier) @function)
84−(function_signature_item (identifier) @function)
85
89
86−; Other identifiers
87
90
88−(type_identifier) @type
91+; -------
89−(primitive_type) @type.builtin
92+; Keywords
90−(field_identifier) @property
93+; -------
91
94
92−(line_comment) @comment
95+(for_expression
93−(block_comment) @comment
96+ "for" @keyword.control)
97+((identifier) @keyword.control
98+ (#match? @keyword.control "^yield$"))
99+[
100+ "while"
101+ "loop"
102+ "in"
103+ "break"
104+ "continue"
94
105
95−"(" @punctuation.bracket
106+ "match"
96−")" @punctuation.bracket
107+ "if"
97−"[" @punctuation.bracket
108+ "else"
98−"]" @punctuation.bracket
109+ "return"
110+
111+ "await"
112+] @keyword.control
113+
114+[
115+ (crate)
116+ (super)
117+ "as"
118+ "use"
119+ "pub"
120+ "mod"
121+ "extern"
122+
123+ "fn"
124+ "struct"
125+ "enum"
126+ "impl"
127+ "where"
128+ "trait"
129+ "for"
130+
131+ "type"
132+ "union"
133+ "unsafe"
134+ "default"
135+ "macro_rules!"
136+
137+ "let"
138+ "ref"
139+ "move"
140+
141+ "dyn"
142+ "static"
143+ "const"
144+ "async"
145+] @keyword
99
146
100−(type_arguments
101− "<" @punctuation.bracket
102− ">" @punctuation.bracket)
103−(type_parameters
104− "<" @punctuation.bracket
105− ">" @punctuation.bracket)
106−
107−"::" @punctuation.delimiter
108−"." @punctuation.delimiter
109−";" @punctuation.delimiter
110−
111−(parameter (identifier) @variable.parameter)
112−(closure_parameters (_) @variable.parameter)
113−
114−(lifetime (identifier) @label)
115−
116−"async" @keyword
117−"break" @keyword
118−"const" @keyword
119−"continue" @keyword
120−(crate) @keyword
121−"default" @keyword
122−"dyn" @keyword
123−"else" @keyword
124−"enum" @keyword
125−"extern" @keyword
126−"fn" @keyword
127−"for" @keyword
128−"if" @keyword
129−"impl" @keyword
130−"in" @keyword
131−"let" @keyword
132−"let" @keyword
133−"loop" @keyword
134−"macro_rules!" @keyword
135−"match" @keyword
136−"mod" @keyword
137−"move" @keyword
138−"pub" @keyword
139−"ref" @keyword
140−"return" @keyword
141−"static" @keyword
142−"struct" @keyword
143−"trait" @keyword
144−"type" @keyword
145−"union" @keyword
146−"unsafe" @keyword
147−"use" @keyword
148−"where" @keyword
149−"while" @keyword
150(mutable_specifier) @keyword.mut
147(mutable_specifier) @keyword.mut
151−(use_list (self) @keyword)
152−(scoped_use_list (self) @keyword)
153−(scoped_identifier (self) @keyword)
154−(super) @keyword
155−"as" @keyword
156
148
157−(self) @variable.builtin
158
149
159−[
160−(char_literal)
161−(string_literal)
162−(raw_string_literal)
163−] @string
164
150
165−(boolean_literal) @constant.builtin
151+; -------
166−(integer_literal) @number
152+; Guess Other Types
167−(float_literal) @number
153+; -------
168
154
169−(escape_sequence) @escape
155+((identifier) @constant
156+ (#match? @constant "^[A-Z][A-Z\\d_]+$"))
157+
158+; ---
159+; PascalCase identifiers in call_expressions (e.g. `Ok()`)
160+; are assumed to be enum constructors.
161+; ---
162+
163+(call_expression
164+ function: [
165+ ((identifier) @type.variant
166+ (#match? @type.variant "^[A-Z]"))
167+ (scoped_identifier
168+ name: ((identifier) @type.variant
169+ (#match? @type.variant "^[A-Z]")))
170+ ])
171+
172+; ---
173+; Assume that types in match arms are enums and not
174+; tuple structs. Same for `if let` expressions.
175+; ---
176+
177+(match_pattern
178+ (scoped_identifier
179+ name: (identifier) @constructor))
180+(tuple_struct_pattern
181+ type: [
182+ ((identifier) @constructor)
183+ (scoped_identifier
184+ name: (identifier) @constructor)
185+ ])
186+(struct_pattern
187+ type: [
188+ ((type_identifier) @constructor)
189+ (scoped_type_identifier
190+ name: (type_identifier) @constructor)
191+ ])
170
192
193+; ---
194+; Other PascalCase identifiers are assumed to be structs.
195+; ---
196+
197+((identifier) @type
198+ (#match? @type "^[A-Z]"))
199+
200+
201+
202+; -------
203+; Functions
204+; -------
205+
206+(call_expression
207+ function: [
208+ ((identifier) @function)
209+ (scoped_identifier
210+ name: (identifier) @function)
211+ (field_expression
212+ field: (field_identifier) @function)
213+ ])
214+(generic_function
215+ function: [
216+ ((identifier) @function)
217+ (scoped_identifier
218+ name: (identifier) @function)
219+ (field_expression
220+ field: (field_identifier) @function.method)
221+ ])
222+
223+(function_item
224+ name: (identifier) @function)
225+
226+; ---
227+; Macros
228+; ---
229+
230+(meta_item
231+ (identifier) @attribute)
171(attribute_item) @attribute
232(attribute_item) @attribute
172(inner_attribute_item) @attribute
233(inner_attribute_item) @attribute
173
234
235+(macro_definition
236+ name: (identifier) @function.macro)
237+(macro_invocation
238+ macro: [
239+ ((identifier) @function.macro)
240+ (scoped_identifier
241+ name: (identifier) @function.macro)
242+ ]
243+ "!" @function.macro)
244+
245+(metavariable) @variable.parameter
246+(fragment_specifier) @variable.parameter
247+
248+
249+
250+; -------
251+; Operators
252+; -------
253+
174[
254[
175−"*"
255+ "*"
176−"'"
256+ "'"
177−"->"
257+ "->"
178−"=>"
258+ "=>"
179−"<="
259+ "<="
180−"="
260+ "="
181−"=="
261+ "=="
182−"!"
262+ "!"
183−"!="
263+ "!="
184−"%"
264+ "%"
185−"%="
265+ "%="
186−"&"
266+ "&"
187−"&="
267+ "&="
188−"&&"
268+ "&&"
189−"|"
269+ "|"
190−"|="
270+ "|="
191−"||"
271+ "||"
192−"^"
272+ "^"
193−"^="
273+ "^="
194−"*"
274+ "*"
195−"*="
275+ "*="
196−"-"
276+ "-"
197−"-="
277+ "-="
198−"+"
278+ "+"
199−"+="
279+ "+="
200−"/"
280+ "/"
201−"/="
281+ "/="
202−">"
282+ ">"
203−"<"
283+ "<"
204−">="
284+ ">="
205−">>"
285+ ">>"
206−"<<"
286+ "<<"
207−">>="
287+ ">>="
208−"@"
288+ "@"
209−".."
289+ ".."
210−"..="
290+ "..="
211−"'"
291+ "'"
212] @operator
292] @operator
213
293
294+
295+
296+; -------
297+; Paths
298+; -------
299+
300+(use_declaration
301+ argument: (identifier) @namespace)
302+(use_wildcard
303+ (identifier) @namespace)
304+(extern_crate_declaration
305+ name: (identifier) @namespace)
306+(mod_item
307+ name: (identifier) @namespace)
308+(scoped_use_list
309+ path: (identifier)? @namespace)
310+(use_list
311+ (identifier) @namespace)
312+(use_as_clause
313+ path: (identifier)? @namespace
314+ alias: (identifier) @namespace)
315+
316+; ---
317+; Remaining Paths
318+; ---
319+
320+(scoped_identifier
321+ path: (identifier)? @namespace
322+ name: (identifier) @namespace)
323+(scoped_type_identifier
324+ path: (identifier) @namespace)
325+
326+
327+
328+; -------
329+; Remaining Identifiers
330+; -------
331+
214"?" @special
332"?" @special
333+
334+(type_identifier) @type
335+(identifier) @variable
336+(field_identifier) @variable