@@ -166,6 +166,7 @@ pub struct HighlightConfig {
166
166
// injected:: Emitted for doc-string injected highlighting like rust source blocks in documentation.
167
167
// intraDocLink:: Emitted for intra doc links in doc-strings.
168
168
// library:: Emitted for items that are defined outside of the current crate.
169
+ // macro:: Emitted for tokens inside macro calls.
169
170
// mutable:: Emitted for mutable locals and statics as well as functions taking `&mut self`.
170
171
// public:: Emitted for items that are from the current crate and are `pub`.
171
172
// reference:: Emitted for locals behind a reference and functions taking `self` by reference.
@@ -240,6 +241,7 @@ fn traverse(
240
241
let mut current_macro: Option < ast:: Macro > = None ;
241
242
let mut macro_highlighter = MacroHighlighter :: default ( ) ;
242
243
let mut inside_attribute = false ;
244
+ let mut inside_macro_call = false ;
243
245
244
246
// Walk all nodes, keeping track of whether we are inside a macro or not.
245
247
// If in macro, expand it first and highlight the expanded code.
@@ -270,46 +272,50 @@ fn traverse(
270
272
inside_attribute = false
271
273
}
272
274
273
- Enter ( NodeOrToken :: Node ( node) ) if ast:: Item :: can_cast ( node. kind ( ) ) => {
274
- match ast:: Item :: cast ( node. clone ( ) ) {
275
- Some ( ast:: Item :: MacroRules ( mac) ) => {
276
- macro_highlighter. init ( ) ;
277
- current_macro = Some ( mac. into ( ) ) ;
278
- continue ;
279
- }
280
- Some ( ast:: Item :: MacroDef ( mac) ) => {
281
- macro_highlighter. init ( ) ;
282
- current_macro = Some ( mac. into ( ) ) ;
283
- continue ;
284
- }
285
- Some ( item) => {
286
- if matches ! ( node. kind( ) , FN | CONST | STATIC ) {
287
- bindings_shadow_count. clear ( ) ;
275
+ Enter ( NodeOrToken :: Node ( node) ) => match ast:: Item :: cast ( node. clone ( ) ) {
276
+ Some ( item) => {
277
+ match item {
278
+ ast:: Item :: MacroRules ( mac) => {
279
+ macro_highlighter. init ( ) ;
280
+ current_macro = Some ( mac. into ( ) ) ;
281
+ continue ;
282
+ }
283
+ ast:: Item :: MacroDef ( mac) => {
284
+ macro_highlighter. init ( ) ;
285
+ current_macro = Some ( mac. into ( ) ) ;
286
+ continue ;
288
287
}
288
+ ast:: Item :: Fn ( _) | ast:: Item :: Const ( _) | ast:: Item :: Static ( _) => {
289
+ bindings_shadow_count. clear ( )
290
+ }
291
+ ast:: Item :: MacroCall ( _) => {
292
+ inside_macro_call = true ;
293
+ }
294
+ _ => ( ) ,
295
+ }
289
296
290
- if attr_or_derive_item. is_none ( ) {
291
- if sema. is_attr_macro_call ( & item) {
292
- attr_or_derive_item = Some ( AttrOrDerive :: Attr ( item) ) ;
293
- } else {
294
- let adt = match item {
295
- ast:: Item :: Enum ( it) => Some ( ast:: Adt :: Enum ( it) ) ,
296
- ast:: Item :: Struct ( it) => Some ( ast:: Adt :: Struct ( it) ) ,
297
- ast:: Item :: Union ( it) => Some ( ast:: Adt :: Union ( it) ) ,
298
- _ => None ,
299
- } ;
300
- match adt {
301
- Some ( adt) if sema. is_derive_annotated ( & adt) => {
302
- attr_or_derive_item =
303
- Some ( AttrOrDerive :: Derive ( ast:: Item :: from ( adt) ) ) ;
304
- }
305
- _ => ( ) ,
297
+ if attr_or_derive_item. is_none ( ) {
298
+ if sema. is_attr_macro_call ( & item) {
299
+ attr_or_derive_item = Some ( AttrOrDerive :: Attr ( item) ) ;
300
+ } else {
301
+ let adt = match item {
302
+ ast:: Item :: Enum ( it) => Some ( ast:: Adt :: Enum ( it) ) ,
303
+ ast:: Item :: Struct ( it) => Some ( ast:: Adt :: Struct ( it) ) ,
304
+ ast:: Item :: Union ( it) => Some ( ast:: Adt :: Union ( it) ) ,
305
+ _ => None ,
306
+ } ;
307
+ match adt {
308
+ Some ( adt) if sema. is_derive_annotated ( & adt) => {
309
+ attr_or_derive_item =
310
+ Some ( AttrOrDerive :: Derive ( ast:: Item :: from ( adt) ) ) ;
306
311
}
312
+ _ => ( ) ,
307
313
}
308
314
}
309
315
}
310
- _ => ( ) ,
311
316
}
312
- }
317
+ _ => ( ) ,
318
+ } ,
313
319
Leave ( NodeOrToken :: Node ( node) ) if ast:: Item :: can_cast ( node. kind ( ) ) => {
314
320
match ast:: Item :: cast ( node. clone ( ) ) {
315
321
Some ( ast:: Item :: MacroRules ( mac) ) => {
@@ -327,6 +333,9 @@ fn traverse(
327
333
{
328
334
attr_or_derive_item = None ;
329
335
}
336
+ Some ( ast:: Item :: MacroCall ( _) ) => {
337
+ inside_macro_call = false ;
338
+ }
330
339
_ => ( ) ,
331
340
}
332
341
}
@@ -476,6 +485,9 @@ fn traverse(
476
485
if inside_attribute {
477
486
highlight |= HlMod :: Attribute
478
487
}
488
+ if inside_macro_call && tt_level > 0 {
489
+ highlight |= HlMod :: Macro
490
+ }
479
491
480
492
hl. add ( HlRange { range, highlight, binding_hash } ) ;
481
493
}
0 commit comments