File tree Expand file tree Collapse file tree 8 files changed +23
-15
lines changed
src/tools/rust-analyzer/crates
syntax_highlighting/test_data Expand file tree Collapse file tree 8 files changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -954,6 +954,10 @@ impl<'db> SemanticsImpl<'db> {
954
954
} ;
955
955
956
956
while let Some ( ( expansion, ref mut tokens) ) = stack. pop ( ) {
957
+ // Reverse the tokens so we prefer first tokens (to accommodate for popping from the
958
+ // back)
959
+ // alternatively we could pop from the front but that would shift the content on every pop
960
+ tokens. reverse ( ) ;
957
961
while let Some ( ( token, ctx) ) = tokens. pop ( ) {
958
962
let was_not_remapped = ( || {
959
963
// First expand into attribute invocations
Original file line number Diff line number Diff line change @@ -301,6 +301,8 @@ pub struct Ranker<'a> {
301
301
}
302
302
303
303
impl < ' a > Ranker < ' a > {
304
+ pub const MAX_RANK : usize = 0b1110 ;
305
+
304
306
pub fn from_token ( token : & ' a syntax:: SyntaxToken ) -> Self {
305
307
let kind = token. kind ( ) ;
306
308
Ranker { kind, text : token. text ( ) , ident_kind : kind. is_any_identifier ( ) }
@@ -317,9 +319,9 @@ impl<'a> Ranker<'a> {
317
319
// anything that mapped into a token tree has likely no semantic information
318
320
let no_tt_parent =
319
321
tok. parent ( ) . map_or ( false , |it| it. kind ( ) != parser:: SyntaxKind :: TOKEN_TREE ) ;
320
- ! ( ( both_idents as usize )
322
+ ( both_idents as usize )
321
323
| ( ( exact_same_kind as usize ) << 1 )
322
324
| ( ( same_text as usize ) << 2 )
323
- | ( ( no_tt_parent as usize ) << 3 ) )
325
+ | ( ( no_tt_parent as usize ) << 3 )
324
326
}
325
327
}
Original file line number Diff line number Diff line change @@ -510,6 +510,7 @@ fn caller$0() {
510
510
expect ! [ [ ] ] ,
511
511
) ;
512
512
}
513
+
513
514
#[ test]
514
515
fn test_call_hierarchy_in_macros_incoming_different_files ( ) {
515
516
check_hierarchy (
@@ -591,9 +592,9 @@ macro_rules! call {
591
592
"# ,
592
593
expect ! [ "callee Function FileId(0) 22..37 30..36" ] ,
593
594
expect ! [ [ r#"
594
- callee Function FileId(0) 38..52 44..50 : FileId(0):44..50
595
595
caller Function FileId(0) 38..52 : FileId(0):44..50
596
- caller Function FileId(1) 130..136 130..136 : FileId(0):44..50"# ] ] ,
596
+ caller Function FileId(1) 130..136 130..136 : FileId(0):44..50
597
+ callee Function FileId(0) 38..52 44..50 : FileId(0):44..50"# ] ] ,
597
598
expect ! [ [ ] ] ,
598
599
) ;
599
600
}
Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ fn hover_offset(
184
184
185
185
let ranker = Ranker :: from_token ( & original_token) ;
186
186
187
- descended. sort_by_cached_key ( |tok| ranker. rank_token ( tok) ) ;
187
+ descended. sort_by_cached_key ( |tok| ! ranker. rank_token ( tok) ) ;
188
188
189
189
let mut res = vec ! [ ] ;
190
190
for token in descended {
Original file line number Diff line number Diff line change @@ -289,7 +289,7 @@ m!(ab$0c);
289
289
*abc*
290
290
291
291
```rust
292
- test::module
292
+ test
293
293
```
294
294
295
295
```rust
@@ -298,11 +298,11 @@ m!(ab$0c);
298
298
299
299
---
300
300
301
- Inner
301
+ Outer
302
302
---
303
303
304
304
```rust
305
- test
305
+ test::module
306
306
```
307
307
308
308
```rust
@@ -311,7 +311,7 @@ m!(ab$0c);
311
311
312
312
---
313
313
314
- Outer
314
+ Inner
315
315
"# ] ] ,
316
316
) ;
317
317
}
Original file line number Diff line number Diff line change @@ -1701,14 +1701,14 @@ fn f() {
1701
1701
}
1702
1702
"# ,
1703
1703
expect ! [ [ r#"
1704
- func Function FileId(0) 137..146 140..144
1704
+ func Function FileId(0) 137..146 140..144 module
1705
1705
1706
- FileId(0) 161..165
1706
+ FileId(0) 181..185
1707
1707
1708
1708
1709
- func Function FileId(0) 137..146 140..144 module
1709
+ func Function FileId(0) 137..146 140..144
1710
1710
1711
- FileId(0) 181..185
1711
+ FileId(0) 161..165
1712
1712
"# ] ] ,
1713
1713
)
1714
1714
}
Original file line number Diff line number Diff line change @@ -397,6 +397,7 @@ fn traverse(
397
397
Some ( AttrOrDerive :: Derive ( _) ) => inside_attribute,
398
398
None => false ,
399
399
} ;
400
+
400
401
let descended_element = if in_macro {
401
402
// Attempt to descend tokens into macro-calls.
402
403
let res = match element {
@@ -412,7 +413,7 @@ fn traverse(
412
413
let tok = tok. value ;
413
414
let my_rank = ranker. rank_token ( & tok) ;
414
415
415
- if my_rank > 0b1110 {
416
+ if my_rank >= Ranker :: MAX_RANK {
416
417
// a rank of 0b1110 means that we have found a maximally interesting
417
418
// token so stop early.
418
419
t = Some ( tok) ;
Original file line number Diff line number Diff line change 50
50
< span class ="brace "> }</ span >
51
51
52
52
< span class ="attribute_bracket attribute "> #</ span > < span class ="attribute_bracket attribute "> [</ span > < span class ="module attribute crate_root library "> proc_macros</ span > < span class ="operator attribute "> ::</ span > < span class ="attribute attribute library "> issue_18089</ span > < span class ="attribute_bracket attribute "> ]</ span >
53
- < span class ="keyword "> fn</ span > < span class ="function declaration "> template</ span > < span class ="parenthesis "> (</ span > < span class ="parenthesis "> )</ span > < span class ="brace "> {</ span > < span class ="brace "> }</ span > </ code > </ pre >
53
+ < span class ="keyword "> fn</ span > < span class ="macro declaration "> template</ span > < span class ="parenthesis "> (</ span > < span class ="parenthesis "> )</ span > < span class ="brace "> {</ span > < span class ="brace "> }</ span > </ code > </ pre >
You can’t perform that action at this time.
0 commit comments