@@ -9,14 +9,15 @@ use ide_db::{
9
9
search:: FileReference ,
10
10
FxIndexMap , RootDatabase ,
11
11
} ;
12
- use syntax:: { ast, AstNode , SyntaxKind :: IDENT , TextRange } ;
12
+ use span:: FileRange ;
13
+ use syntax:: { ast, AstNode , SyntaxKind :: IDENT } ;
13
14
14
15
use crate :: { goto_definition, FilePosition , NavigationTarget , RangeInfo , TryToNav } ;
15
16
16
17
#[ derive( Debug , Clone ) ]
17
18
pub struct CallItem {
18
19
pub target : NavigationTarget ,
19
- pub ranges : Vec < TextRange > ,
20
+ pub ranges : Vec < FileRange > ,
20
21
}
21
22
22
23
pub ( crate ) fn call_hierarchy (
@@ -61,9 +62,10 @@ pub(crate) fn incoming_calls(
61
62
def. try_to_nav ( sema. db )
62
63
} ) ;
63
64
if let Some ( nav) = nav {
64
- calls. add ( nav. call_site , sema. original_range ( name. syntax ( ) ) . range ) ;
65
+ let range = sema. original_range ( name. syntax ( ) ) ;
66
+ calls. add ( nav. call_site , range) ;
65
67
if let Some ( other) = nav. def_site {
66
- calls. add ( other, sema . original_range ( name . syntax ( ) ) . range ) ;
68
+ calls. add ( other, range) ;
67
69
}
68
70
}
69
71
}
@@ -107,12 +109,13 @@ pub(crate) fn outgoing_calls(
107
109
hir:: CallableKind :: TupleStruct ( it) => it. try_to_nav ( db) ,
108
110
_ => None ,
109
111
}
110
- . zip ( Some ( expr. syntax ( ) . text_range ( ) ) )
112
+ . zip ( Some ( sema . original_range ( expr. syntax ( ) ) ) )
111
113
}
112
114
ast:: CallableExpr :: MethodCall ( expr) => {
113
- let range = expr. name_ref ( ) ?. syntax ( ) . text_range ( ) ;
114
115
let function = sema. resolve_method_call ( & expr) ?;
115
- function. try_to_nav ( db) . zip ( Some ( range) )
116
+ function
117
+ . try_to_nav ( db)
118
+ . zip ( Some ( sema. original_range ( expr. name_ref ( ) ?. syntax ( ) ) ) )
116
119
}
117
120
} ?;
118
121
Some ( nav_target. into_iter ( ) . zip ( iter:: repeat ( range) ) )
@@ -125,11 +128,11 @@ pub(crate) fn outgoing_calls(
125
128
126
129
#[ derive( Default ) ]
127
130
struct CallLocations {
128
- funcs : FxIndexMap < NavigationTarget , Vec < TextRange > > ,
131
+ funcs : FxIndexMap < NavigationTarget , Vec < FileRange > > ,
129
132
}
130
133
131
134
impl CallLocations {
132
- fn add ( & mut self , target : NavigationTarget , range : TextRange ) {
135
+ fn add ( & mut self , target : NavigationTarget , range : FileRange ) {
133
136
self . funcs . entry ( target) . or_default ( ) . push ( range) ;
134
137
}
135
138
@@ -153,7 +156,14 @@ mod tests {
153
156
expected_outgoing : Expect ,
154
157
) {
155
158
fn debug_render ( item : crate :: CallItem ) -> String {
156
- format ! ( "{} : {:?}" , item. target. debug_render( ) , item. ranges)
159
+ format ! (
160
+ "{} : {}" ,
161
+ item. target. debug_render( ) ,
162
+ item. ranges. iter( ) . format_with( ", " , |range, f| f( & format_args!(
163
+ "{:?}:{:?}" ,
164
+ range. file_id, range. range
165
+ ) ) )
166
+ )
157
167
}
158
168
159
169
let ( analysis, pos) = fixture:: position ( ra_fixture) ;
@@ -183,7 +193,7 @@ fn caller() {
183
193
}
184
194
"# ,
185
195
expect ! [ [ "callee Function FileId(0) 0..14 3..9" ] ] ,
186
- expect ! [ [ "caller Function FileId(0) 15..44 18..24 : [ 33..39]" ] ] ,
196
+ expect ! [ "caller Function FileId(0) 15..44 18..24 : FileId(0): 33..39" ] ,
187
197
expect ! [ [ ] ] ,
188
198
) ;
189
199
}
@@ -199,7 +209,7 @@ fn caller() {
199
209
}
200
210
"# ,
201
211
expect ! [ [ "callee Function FileId(0) 0..14 3..9" ] ] ,
202
- expect ! [ [ "caller Function FileId(0) 15..44 18..24 : [ 33..39]" ] ] ,
212
+ expect ! [ "caller Function FileId(0) 15..44 18..24 : FileId(0): 33..39" ] ,
203
213
expect ! [ [ ] ] ,
204
214
) ;
205
215
}
@@ -216,7 +226,7 @@ fn caller() {
216
226
}
217
227
"# ,
218
228
expect ! [ [ "callee Function FileId(0) 0..14 3..9" ] ] ,
219
- expect ! [ [ "caller Function FileId(0) 15..58 18..24 : [ 33..39, 47..53]" ] ] ,
229
+ expect ! [ "caller Function FileId(0) 15..58 18..24 : FileId(0): 33..39, FileId(0): 47..53" ] ,
220
230
expect ! [ [ ] ] ,
221
231
) ;
222
232
}
@@ -236,9 +246,9 @@ fn caller2() {
236
246
}
237
247
"# ,
238
248
expect ! [ [ "callee Function FileId(0) 0..14 3..9" ] ] ,
239
- expect ! [ [ "
240
- caller1 Function FileId(0) 15..45 18..25 : [ 34..40]
241
- caller2 Function FileId(0) 47..77 50..57 : [ 66..72]" ] ] ,
249
+ expect ! [ [ r# "
250
+ caller1 Function FileId(0) 15..45 18..25 : FileId(0): 34..40
251
+ caller2 Function FileId(0) 47..77 50..57 : FileId(0): 66..72"# ] ] ,
242
252
expect ! [ [ ] ] ,
243
253
) ;
244
254
}
@@ -265,8 +275,8 @@ mod tests {
265
275
"# ,
266
276
expect ! [ [ "callee Function FileId(0) 0..14 3..9" ] ] ,
267
277
expect ! [ [ r#"
268
- caller1 Function FileId(0) 15..45 18..25 : [ 34..40]
269
- test_caller Function FileId(0) 95..149 110..121 tests : [ 134..140] "# ] ] ,
278
+ caller1 Function FileId(0) 15..45 18..25 : FileId(0): 34..40
279
+ test_caller Function FileId(0) 95..149 110..121 tests : FileId(0): 134..140"# ] ] ,
270
280
expect ! [ [ ] ] ,
271
281
) ;
272
282
}
@@ -287,7 +297,7 @@ fn caller() {
287
297
pub fn callee() {}
288
298
"# ,
289
299
expect ! [ "callee Function FileId(1) 0..18 7..13 foo" ] ,
290
- expect ! [ [ "caller Function FileId(0) 27..56 30..36 : [ 45..51]" ] ] ,
300
+ expect ! [ "caller Function FileId(0) 27..56 30..36 : FileId(0): 45..51" ] ,
291
301
expect ! [ [ ] ] ,
292
302
) ;
293
303
}
@@ -305,7 +315,7 @@ fn call$0er() {
305
315
"# ,
306
316
expect ! [ [ "caller Function FileId(0) 15..58 18..24" ] ] ,
307
317
expect ! [ [ ] ] ,
308
- expect ! [ [ "callee Function FileId(0) 0..14 3..9 : [ 33..39, 47..53]" ] ] ,
318
+ expect ! [ "callee Function FileId(0) 0..14 3..9 : FileId(0): 33..39, FileId(0): 47..53" ] ,
309
319
) ;
310
320
}
311
321
@@ -326,7 +336,7 @@ pub fn callee() {}
326
336
"# ,
327
337
expect ! [ [ "caller Function FileId(0) 27..56 30..36" ] ] ,
328
338
expect ! [ [ ] ] ,
329
- expect ! [ "callee Function FileId(1) 0..18 7..13 foo : [ 45..51] " ] ,
339
+ expect ! [ "callee Function FileId(1) 0..18 7..13 foo : FileId(0): 45..51" ] ,
330
340
) ;
331
341
}
332
342
@@ -348,8 +358,8 @@ fn caller3() {
348
358
}
349
359
"# ,
350
360
expect ! [ [ "caller2 Function FileId(0) 33..64 36..43" ] ] ,
351
- expect ! [ [ "caller1 Function FileId(0) 0..31 3..10 : [ 19..26]" ] ] ,
352
- expect ! [ [ "caller3 Function FileId(0) 66..83 69..76 : [ 52..59]" ] ] ,
361
+ expect ! [ "caller1 Function FileId(0) 0..31 3..10 : FileId(0): 19..26" ] ,
362
+ expect ! [ "caller3 Function FileId(0) 66..83 69..76 : FileId(0): 52..59" ] ,
353
363
) ;
354
364
}
355
365
@@ -368,8 +378,8 @@ fn main() {
368
378
}
369
379
"# ,
370
380
expect ! [ [ "a Function FileId(0) 0..18 3..4" ] ] ,
371
- expect ! [ [ "main Function FileId(0) 31..52 34..38 : [ 47..48]" ] ] ,
372
- expect ! [ [ "b Function FileId(0) 20..29 23..24 : [ 13..14]" ] ] ,
381
+ expect ! [ "main Function FileId(0) 31..52 34..38 : FileId(0): 47..48" ] ,
382
+ expect ! [ "b Function FileId(0) 20..29 23..24 : FileId(0): 13..14" ] ,
373
383
) ;
374
384
375
385
check_hierarchy (
@@ -385,7 +395,7 @@ fn main() {
385
395
}
386
396
"# ,
387
397
expect ! [ [ "b Function FileId(0) 20..29 23..24" ] ] ,
388
- expect ! [ [ "a Function FileId(0) 0..18 3..4 : [ 13..14]" ] ] ,
398
+ expect ! [ "a Function FileId(0) 0..18 3..4 : FileId(0): 13..14" ] ,
389
399
expect ! [ [ ] ] ,
390
400
) ;
391
401
}
@@ -410,7 +420,7 @@ fn caller() {
410
420
}
411
421
"# ,
412
422
expect ! [ [ r#"callee Function FileId(0) 144..159 152..158"# ] ] ,
413
- expect ! [ [ r# "caller Function FileId(0) 160..194 163..169 : [ 184..190]"# ] ] ,
423
+ expect ! [ "caller Function FileId(0) 160..194 163..169 : FileId(0): 184..190" ] ,
414
424
expect ! [ [ ] ] ,
415
425
) ;
416
426
check_hierarchy (
@@ -431,7 +441,7 @@ fn caller() {
431
441
}
432
442
"# ,
433
443
expect ! [ [ r#"callee Function FileId(0) 144..159 152..158"# ] ] ,
434
- expect ! [ [ r# "caller Function FileId(0) 160..194 163..169 : [ 184..190]"# ] ] ,
444
+ expect ! [ "caller Function FileId(0) 160..194 163..169 : FileId(0): 184..190" ] ,
435
445
expect ! [ [ ] ] ,
436
446
) ;
437
447
}
@@ -461,6 +471,148 @@ fn caller$0() {
461
471
expect ! [ [ ] ] ,
462
472
) ;
463
473
}
474
+ #[ test]
475
+ fn test_call_hierarchy_in_macros_incoming_different_files ( ) {
476
+ check_hierarchy (
477
+ r#"
478
+ //- /lib.rs
479
+ #[macro_use]
480
+ mod foo;
481
+ define!(callee)
482
+ fn caller() {
483
+ call!(call$0ee);
484
+ }
485
+ //- /foo.rs
486
+ macro_rules! define {
487
+ ($ident:ident) => {
488
+ fn $ident {}
489
+ }
490
+ }
491
+ macro_rules! call {
492
+ ($ident:ident) => {
493
+ $ident()
494
+ }
495
+ }
496
+ "# ,
497
+ expect ! [ "callee Function FileId(0) 22..37 30..36" ] ,
498
+ expect ! [ "caller Function FileId(0) 38..72 41..47 : FileId(0):62..68" ] ,
499
+ expect ! [ [ ] ] ,
500
+ ) ;
501
+ check_hierarchy (
502
+ r#"
503
+ //- /lib.rs
504
+ #[macro_use]
505
+ mod foo;
506
+ define!(cal$0lee)
507
+ fn caller() {
508
+ call!(callee);
509
+ }
510
+ //- /foo.rs
511
+ macro_rules! define {
512
+ ($ident:ident) => {
513
+ fn $ident {}
514
+ }
515
+ }
516
+ macro_rules! call {
517
+ ($ident:ident) => {
518
+ $ident()
519
+ }
520
+ }
521
+ "# ,
522
+ expect ! [ "callee Function FileId(0) 22..37 30..36" ] ,
523
+ expect ! [ "caller Function FileId(0) 38..72 41..47 : FileId(0):62..68" ] ,
524
+ expect ! [ [ ] ] ,
525
+ ) ;
526
+ check_hierarchy (
527
+ r#"
528
+ //- /lib.rs
529
+ #[macro_use]
530
+ mod foo;
531
+ define!(cal$0lee)
532
+ call!(callee);
533
+ //- /foo.rs
534
+ macro_rules! define {
535
+ ($ident:ident) => {
536
+ fn $ident {}
537
+ }
538
+ }
539
+ macro_rules! call {
540
+ ($ident:ident) => {
541
+ fn caller() {
542
+ $ident()
543
+ }
544
+ fn $ident() {
545
+ $ident()
546
+ }
547
+ }
548
+ }
549
+ "# ,
550
+ expect ! [ "callee Function FileId(0) 22..37 30..36" ] ,
551
+ expect ! [ [ r#"
552
+ callee Function FileId(0) 38..52 44..50 : FileId(0):44..50
553
+ caller Function FileId(0) 38..52 : FileId(0):44..50
554
+ caller Function FileId(1) 130..136 130..136 : FileId(0):44..50"# ] ] ,
555
+ expect ! [ [ ] ] ,
556
+ ) ;
557
+ }
558
+
559
+ #[ test]
560
+ fn test_call_hierarchy_in_macros_outgoing_different_files ( ) {
561
+ check_hierarchy (
562
+ r#"
563
+ //- /lib.rs
564
+ #[macro_use]
565
+ mod foo;
566
+ define!(callee)
567
+ fn caller$0() {
568
+ call!(callee);
569
+ }
570
+ //- /foo.rs
571
+ macro_rules! define {
572
+ ($ident:ident) => {
573
+ fn $ident {}
574
+ }
575
+ }
576
+ macro_rules! call {
577
+ ($ident:ident) => {
578
+ $ident()
579
+ callee()
580
+ }
581
+ }
582
+ "# ,
583
+ expect ! [ "caller Function FileId(0) 38..72 41..47" ] ,
584
+ expect ! [ [ ] ] ,
585
+ // FIXME
586
+ expect ! [ [ ] ] ,
587
+ ) ;
588
+ check_hierarchy (
589
+ r#"
590
+ //- /lib.rs
591
+ #[macro_use]
592
+ mod foo;
593
+ define!(callee)
594
+ fn caller$0() {
595
+ call!(callee);
596
+ }
597
+ //- /foo.rs
598
+ macro_rules! define {
599
+ () => {
600
+ fn callee {}
601
+ }
602
+ }
603
+ macro_rules! call {
604
+ ($ident:ident) => {
605
+ $ident()
606
+ callee()
607
+ }
608
+ }
609
+ "# ,
610
+ expect ! [ "caller Function FileId(0) 38..72 41..47" ] ,
611
+ expect ! [ [ ] ] ,
612
+ // FIXME
613
+ expect ! [ [ ] ] ,
614
+ ) ;
615
+ }
464
616
465
617
#[ test]
466
618
fn test_trait_method_call_hierarchy ( ) {
@@ -481,7 +633,7 @@ fn caller() {
481
633
}
482
634
"# ,
483
635
expect ! [ "callee Function FileId(0) 15..27 18..24 T1" ] ,
484
- expect ! [ [ "caller Function FileId(0) 82..115 85..91 : [ 104..110]" ] ] ,
636
+ expect ! [ "caller Function FileId(0) 82..115 85..91 : FileId(0): 104..110" ] ,
485
637
expect ! [ [ ] ] ,
486
638
) ;
487
639
}
0 commit comments