Skip to content

Commit 41e23b4

Browse files
authored
Tweaks to code highlighting. Closes #149. (#150)
* Tweaks to code highlighting. Closes #149. * Remove contradictory rule for `as`. `as` has three completely unrelated uses in Rust. - type cast: `nvalues as u32` - import alias: `use std::collections::HashMap as Map;` - qualify a method with both type and trait: `<TcpStream as Write>::write_all(s, bytes)?;` In all cases `as` appears between two things, so `operator` isn't bad. I think `keyword` is a little better though. (It would also be possible to use `operator only` for casts, but that seems excessive to me.)
1 parent 0f14a10 commit 41e23b4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

queries/highlights.scm

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,25 @@
1212
path: (scoped_identifier
1313
name: (identifier) @type))
1414
(#match? @type "^[A-Z]"))
15+
((scoped_type_identifier
16+
path: (identifier) @type)
17+
(#match? @type "^[A-Z]"))
18+
((scoped_type_identifier
19+
path: (scoped_identifier
20+
name: (identifier) @type))
21+
(#match? @type "^[A-Z]"))
1522

1623
; Assume other uppercase names are enum constructors
1724
((identifier) @constructor
1825
(#match? @constructor "^[A-Z]"))
1926

27+
; Assume all qualified names in struct patterns are enum constructors. (They're
28+
; either that, or struct names; highlighting both as constructors seems to be
29+
; the less glaring choice of error, visually.)
30+
(struct_pattern
31+
type: (scoped_type_identifier
32+
name: (type_identifier) @constructor))
33+
2034
; Function calls
2135

2236
(call_expression
@@ -80,6 +94,9 @@
8094

8195
(lifetime (identifier) @label)
8296

97+
"as" @keyword
98+
"async" @keyword
99+
"await" @keyword
83100
"break" @keyword
84101
"const" @keyword
85102
"continue" @keyword
@@ -94,7 +111,6 @@
94111
"impl" @keyword
95112
"in" @keyword
96113
"let" @keyword
97-
"let" @keyword
98114
"loop" @keyword
99115
"macro_rules!" @keyword
100116
"match" @keyword
@@ -112,6 +128,7 @@
112128
"use" @keyword
113129
"where" @keyword
114130
"while" @keyword
131+
(crate) @keyword
115132
(mutable_specifier) @keyword
116133
(use_list (self) @keyword)
117134
(scoped_use_list (self) @keyword)
@@ -133,7 +150,6 @@
133150
(attribute_item) @attribute
134151
(inner_attribute_item) @attribute
135152

136-
"as" @operator
137153
"*" @operator
138154
"&" @operator
139155
"'" @operator

0 commit comments

Comments
 (0)