@@ -30,8 +30,8 @@ pub struct Annotation {
30
30
#[ derive( Debug ) ]
31
31
pub enum AnnotationKind {
32
32
Runnable ( Runnable ) ,
33
- HasImpls { position : FilePosition , data : Option < Vec < NavigationTarget > > } ,
34
- HasReferences { position : FilePosition , data : Option < Vec < FileRange > > } ,
33
+ HasImpls { file_id : FileId , data : Option < Vec < NavigationTarget > > } ,
34
+ HasReferences { file_id : FileId , data : Option < Vec < FileRange > > } ,
35
35
}
36
36
37
37
pub struct AnnotationConfig {
@@ -83,10 +83,7 @@ pub(crate) fn annotations(
83
83
. for_each ( |range| {
84
84
annotations. push ( Annotation {
85
85
range,
86
- kind : AnnotationKind :: HasReferences {
87
- position : FilePosition { file_id, offset : range. start ( ) } ,
88
- data : None ,
89
- } ,
86
+ kind : AnnotationKind :: HasReferences { file_id, data : None } ,
90
87
} )
91
88
} )
92
89
}
@@ -107,27 +104,19 @@ pub(crate) fn annotations(
107
104
_ => None ,
108
105
} ;
109
106
110
- let ( range, offset ) = match range {
111
- Some ( range) => ( range, range . start ( ) ) ,
107
+ let range = match range {
108
+ Some ( range) => range,
112
109
None => return ,
113
110
} ;
114
111
115
112
if config. annotate_impls && !matches ! ( def, Definition :: Const ( _) ) {
116
- annotations. push ( Annotation {
117
- range,
118
- kind : AnnotationKind :: HasImpls {
119
- position : FilePosition { file_id, offset } ,
120
- data : None ,
121
- } ,
122
- } ) ;
113
+ annotations
114
+ . push ( Annotation { range, kind : AnnotationKind :: HasImpls { file_id, data : None } } ) ;
123
115
}
124
116
if config. annotate_references {
125
117
annotations. push ( Annotation {
126
118
range,
127
- kind : AnnotationKind :: HasReferences {
128
- position : FilePosition { file_id, offset } ,
129
- data : None ,
130
- } ,
119
+ kind : AnnotationKind :: HasReferences { file_id, data : None } ,
131
120
} ) ;
132
121
}
133
122
@@ -149,10 +138,7 @@ pub(crate) fn annotations(
149
138
annotations. extend ( find_all_methods ( db, file_id) . into_iter ( ) . map (
150
139
|FileRange { file_id, range } | Annotation {
151
140
range,
152
- kind : AnnotationKind :: HasReferences {
153
- position : FilePosition { file_id, offset : range. start ( ) } ,
154
- data : None ,
155
- } ,
141
+ kind : AnnotationKind :: HasReferences { file_id, data : None } ,
156
142
} ,
157
143
) ) ;
158
144
}
@@ -161,12 +147,19 @@ pub(crate) fn annotations(
161
147
}
162
148
163
149
pub ( crate ) fn resolve_annotation ( db : & RootDatabase , mut annotation : Annotation ) -> Annotation {
164
- match & mut annotation. kind {
165
- AnnotationKind :: HasImpls { position, data } => {
166
- * data = goto_implementation ( db, * position) . map ( |range| range. info ) ;
150
+ match annotation. kind {
151
+ AnnotationKind :: HasImpls { file_id, ref mut data } => {
152
+ * data =
153
+ goto_implementation ( db, FilePosition { file_id, offset : annotation. range . start ( ) } )
154
+ . map ( |range| range. info ) ;
167
155
}
168
- AnnotationKind :: HasReferences { position, data } => {
169
- * data = find_all_refs ( & Semantics :: new ( db) , * position, None ) . map ( |result| {
156
+ AnnotationKind :: HasReferences { file_id, ref mut data } => {
157
+ * data = find_all_refs (
158
+ & Semantics :: new ( db) ,
159
+ FilePosition { file_id, offset : annotation. range . start ( ) } ,
160
+ None ,
161
+ )
162
+ . map ( |result| {
170
163
result
171
164
. into_iter ( )
172
165
. flat_map ( |res| res. references )
@@ -254,12 +247,9 @@ fn main() {
254
247
Annotation {
255
248
range: 6..10,
256
249
kind: HasReferences {
257
- position: FilePosition {
258
- file_id: FileId(
259
- 0,
260
- ),
261
- offset: 6,
262
- },
250
+ file_id: FileId(
251
+ 0,
252
+ ),
263
253
data: Some(
264
254
[
265
255
FileRange {
@@ -275,12 +265,9 @@ fn main() {
275
265
Annotation {
276
266
range: 30..36,
277
267
kind: HasReferences {
278
- position: FilePosition {
279
- file_id: FileId(
280
- 0,
281
- ),
282
- offset: 30,
283
- },
268
+ file_id: FileId(
269
+ 0,
270
+ ),
284
271
data: Some(
285
272
[],
286
273
),
@@ -289,12 +276,9 @@ fn main() {
289
276
Annotation {
290
277
range: 53..57,
291
278
kind: HasReferences {
292
- position: FilePosition {
293
- file_id: FileId(
294
- 0,
295
- ),
296
- offset: 53,
297
- },
279
+ file_id: FileId(
280
+ 0,
281
+ ),
298
282
data: Some(
299
283
[],
300
284
),
@@ -339,12 +323,9 @@ fn main() {
339
323
Annotation {
340
324
range: 7..11,
341
325
kind: HasImpls {
342
- position: FilePosition {
343
- file_id: FileId(
344
- 0,
345
- ),
346
- offset: 7,
347
- },
326
+ file_id: FileId(
327
+ 0,
328
+ ),
348
329
data: Some(
349
330
[],
350
331
),
@@ -353,12 +334,9 @@ fn main() {
353
334
Annotation {
354
335
range: 7..11,
355
336
kind: HasReferences {
356
- position: FilePosition {
357
- file_id: FileId(
358
- 0,
359
- ),
360
- offset: 7,
361
- },
337
+ file_id: FileId(
338
+ 0,
339
+ ),
362
340
data: Some(
363
341
[
364
342
FileRange {
@@ -374,12 +352,9 @@ fn main() {
374
352
Annotation {
375
353
range: 17..21,
376
354
kind: HasReferences {
377
- position: FilePosition {
378
- file_id: FileId(
379
- 0,
380
- ),
381
- offset: 17,
382
- },
355
+ file_id: FileId(
356
+ 0,
357
+ ),
383
358
data: Some(
384
359
[],
385
360
),
@@ -428,12 +403,9 @@ fn main() {
428
403
Annotation {
429
404
range: 7..11,
430
405
kind: HasImpls {
431
- position: FilePosition {
432
- file_id: FileId(
433
- 0,
434
- ),
435
- offset: 7,
436
- },
406
+ file_id: FileId(
407
+ 0,
408
+ ),
437
409
data: Some(
438
410
[
439
411
NavigationTarget {
@@ -452,12 +424,9 @@ fn main() {
452
424
Annotation {
453
425
range: 7..11,
454
426
kind: HasReferences {
455
- position: FilePosition {
456
- file_id: FileId(
457
- 0,
458
- ),
459
- offset: 7,
460
- },
427
+ file_id: FileId(
428
+ 0,
429
+ ),
461
430
data: Some(
462
431
[
463
432
FileRange {
@@ -479,12 +448,9 @@ fn main() {
479
448
Annotation {
480
449
range: 20..31,
481
450
kind: HasImpls {
482
- position: FilePosition {
483
- file_id: FileId(
484
- 0,
485
- ),
486
- offset: 20,
487
- },
451
+ file_id: FileId(
452
+ 0,
453
+ ),
488
454
data: Some(
489
455
[
490
456
NavigationTarget {
@@ -503,12 +469,9 @@ fn main() {
503
469
Annotation {
504
470
range: 20..31,
505
471
kind: HasReferences {
506
- position: FilePosition {
507
- file_id: FileId(
508
- 0,
509
- ),
510
- offset: 20,
511
- },
472
+ file_id: FileId(
473
+ 0,
474
+ ),
512
475
data: Some(
513
476
[
514
477
FileRange {
@@ -524,12 +487,9 @@ fn main() {
524
487
Annotation {
525
488
range: 69..73,
526
489
kind: HasReferences {
527
- position: FilePosition {
528
- file_id: FileId(
529
- 0,
530
- ),
531
- offset: 69,
532
- },
490
+ file_id: FileId(
491
+ 0,
492
+ ),
533
493
data: Some(
534
494
[],
535
495
),
@@ -570,12 +530,9 @@ fn main() {}
570
530
Annotation {
571
531
range: 3..7,
572
532
kind: HasReferences {
573
- position: FilePosition {
574
- file_id: FileId(
575
- 0,
576
- ),
577
- offset: 3,
578
- },
533
+ file_id: FileId(
534
+ 0,
535
+ ),
579
536
data: Some(
580
537
[],
581
538
),
@@ -624,12 +581,9 @@ fn main() {
624
581
Annotation {
625
582
range: 7..11,
626
583
kind: HasImpls {
627
- position: FilePosition {
628
- file_id: FileId(
629
- 0,
630
- ),
631
- offset: 7,
632
- },
584
+ file_id: FileId(
585
+ 0,
586
+ ),
633
587
data: Some(
634
588
[
635
589
NavigationTarget {
@@ -648,12 +602,9 @@ fn main() {
648
602
Annotation {
649
603
range: 7..11,
650
604
kind: HasReferences {
651
- position: FilePosition {
652
- file_id: FileId(
653
- 0,
654
- ),
655
- offset: 7,
656
- },
605
+ file_id: FileId(
606
+ 0,
607
+ ),
657
608
data: Some(
658
609
[
659
610
FileRange {
@@ -675,12 +626,9 @@ fn main() {
675
626
Annotation {
676
627
range: 33..44,
677
628
kind: HasReferences {
678
- position: FilePosition {
679
- file_id: FileId(
680
- 0,
681
- ),
682
- offset: 33,
683
- },
629
+ file_id: FileId(
630
+ 0,
631
+ ),
684
632
data: Some(
685
633
[
686
634
FileRange {
@@ -696,12 +644,9 @@ fn main() {
696
644
Annotation {
697
645
range: 61..65,
698
646
kind: HasReferences {
699
- position: FilePosition {
700
- file_id: FileId(
701
- 0,
702
- ),
703
- offset: 61,
704
- },
647
+ file_id: FileId(
648
+ 0,
649
+ ),
705
650
data: Some(
706
651
[],
707
652
),
@@ -795,12 +740,9 @@ mod tests {
795
740
Annotation {
796
741
range: 3..7,
797
742
kind: HasReferences {
798
- position: FilePosition {
799
- file_id: FileId(
800
- 0,
801
- ),
802
- offset: 3,
803
- },
743
+ file_id: FileId(
744
+ 0,
745
+ ),
804
746
data: Some(
805
747
[],
806
748
),
0 commit comments