@@ -197,7 +197,7 @@ fn traverse(
197
197
let mut bindings_shadow_count: FxHashMap < Name , u32 > = FxHashMap :: default ( ) ;
198
198
199
199
let mut current_macro_call: Option < ast:: MacroCall > = None ;
200
- let mut current_attr_macro_call = None ;
200
+ let mut current_attr_call = None ;
201
201
let mut current_macro: Option < ast:: Macro > = None ;
202
202
let mut macro_highlighter = MacroHighlighter :: default ( ) ;
203
203
let mut inside_attribute = false ;
@@ -236,7 +236,7 @@ fn traverse(
236
236
} ,
237
237
ast:: Item ( item) => {
238
238
if sema. is_attr_macro_call( & item) {
239
- current_attr_macro_call = Some ( item) ;
239
+ current_attr_call = Some ( item) ;
240
240
}
241
241
} ,
242
242
ast:: Attr ( __) => inside_attribute = true ,
@@ -257,8 +257,8 @@ fn traverse(
257
257
macro_highlighter = MacroHighlighter :: default ( ) ;
258
258
} ,
259
259
ast:: Item ( item) => {
260
- if current_attr_macro_call == Some ( item) {
261
- current_attr_macro_call = None ;
260
+ if current_attr_call == Some ( item) {
261
+ current_attr_call = None ;
262
262
}
263
263
} ,
264
264
ast:: Attr ( __) => inside_attribute = false ,
@@ -287,34 +287,28 @@ fn traverse(
287
287
}
288
288
}
289
289
290
- let element_to_highlight = if current_macro_call. is_some ( ) && element. kind ( ) != COMMENT {
290
+ let descend_token = ( current_macro_call. is_some ( ) || current_attr_call. is_some ( ) )
291
+ && element. kind ( ) != COMMENT ;
292
+ let element_to_highlight = if descend_token {
291
293
// Inside a macro -- expand it first
292
294
let token = match element. clone ( ) . into_token ( ) {
293
- Some ( it) if it. parent ( ) . map_or ( false , |it| it. kind ( ) == TOKEN_TREE ) => it,
294
- _ => continue ,
295
- } ;
296
- let token = sema. descend_into_macros ( token. clone ( ) ) ;
297
- match token. parent ( ) {
298
- Some ( parent) => {
299
- // We only care Name and Name_ref
300
- match ( token. kind ( ) , parent. kind ( ) ) {
301
- ( IDENT , NAME | NAME_REF ) => parent. into ( ) ,
302
- _ => token. into ( ) ,
295
+ Some ( it) if current_macro_call. is_some ( ) => {
296
+ let not_in_tt = it. parent ( ) . map_or ( true , |it| it. kind ( ) != TOKEN_TREE ) ;
297
+ if not_in_tt {
298
+ continue ;
303
299
}
300
+ it
304
301
}
305
- None => token. into ( ) ,
306
- }
307
- } else if current_attr_macro_call. is_some ( ) {
308
- let token = match element. clone ( ) . into_token ( ) {
309
302
Some ( it) => it,
310
303
_ => continue ,
311
304
} ;
312
- let token = sema. descend_into_macros ( token. clone ( ) ) ;
305
+ let token = sema. descend_into_macros ( token) ;
313
306
match token. parent ( ) {
314
307
Some ( parent) => {
315
308
// We only care Name and Name_ref
316
309
match ( token. kind ( ) , parent. kind ( ) ) {
317
- ( IDENT , NAME | NAME_REF ) => parent. into ( ) ,
310
+ ( T ! [ ident] , NAME | NAME_REF ) => parent. into ( ) ,
311
+ ( T ! [ self ] | T ! [ super ] | T ! [ crate ] , NAME_REF ) => parent. into ( ) ,
318
312
_ => token. into ( ) ,
319
313
}
320
314
}
@@ -324,11 +318,12 @@ fn traverse(
324
318
element. clone ( )
325
319
} ;
326
320
327
- if let Some ( token) = element. as_token ( ) . cloned ( ) . and_then ( ast:: String :: cast) {
321
+ if let Some ( token) = element. into_token ( ) . and_then ( ast:: String :: cast) {
328
322
if token. is_raw ( ) {
329
- let expanded = element_to_highlight. as_token ( ) . unwrap ( ) . clone ( ) ;
330
- if inject:: ra_fixture ( hl, sema, token, expanded) . is_some ( ) {
331
- continue ;
323
+ if let Some ( expanded) = element_to_highlight. as_token ( ) {
324
+ if inject:: ra_fixture ( hl, sema, token, expanded. clone ( ) ) . is_some ( ) {
325
+ continue ;
326
+ }
332
327
}
333
328
}
334
329
}
@@ -351,7 +346,7 @@ fn traverse(
351
346
hl. add ( HlRange { range, highlight, binding_hash } ) ;
352
347
}
353
348
354
- if let Some ( string) = element_to_highlight. as_token ( ) . cloned ( ) . and_then ( ast:: String :: cast) {
349
+ if let Some ( string) = element_to_highlight. into_token ( ) . and_then ( ast:: String :: cast) {
355
350
highlight_format_string ( hl, & string, range) ;
356
351
// Highlight escape sequences
357
352
if let Some ( char_ranges) = string. char_ranges ( ) {
@@ -376,9 +371,8 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
376
371
let range_start = name_ref. syntax ( ) . text_range ( ) . start ( ) ;
377
372
let mut range_end = name_ref. syntax ( ) . text_range ( ) . end ( ) ;
378
373
for sibling in path. syntax ( ) . siblings_with_tokens ( Direction :: Next ) {
379
- match sibling. kind ( ) {
380
- T ! [ !] | IDENT => range_end = sibling. text_range ( ) . end ( ) ,
381
- _ => ( ) ,
374
+ if let T ! [ !] | T ! [ ident] = sibling. kind ( ) {
375
+ range_end = sibling. text_range ( ) . end ( ) ;
382
376
}
383
377
}
384
378
0 commit comments