@@ -17,8 +17,12 @@ use syntax::print::pprust;
17
17
use syntax:: symbol:: Symbol ;
18
18
use syntax_pos:: Span ;
19
19
20
+ use std:: path:: PathBuf ;
21
+
20
22
use data:: { self , Visibility , SigElement } ;
21
23
24
+ use rls_data:: { SpanData , CratePreludeData } ;
25
+
22
26
// FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet
23
27
pub trait Lower {
24
28
type Target ;
@@ -36,41 +40,26 @@ pub fn null_def_id() -> DefId {
36
40
}
37
41
}
38
42
39
- #[ derive( Clone , Debug , RustcEncodable ) ]
40
- pub struct SpanData {
41
- pub file_name : String ,
42
- pub byte_start : u32 ,
43
- pub byte_end : u32 ,
44
- /// 1-based.
45
- pub line_start : usize ,
46
- pub line_end : usize ,
47
- /// 1-based, character offset.
48
- pub column_start : usize ,
49
- pub column_end : usize ,
50
- }
51
-
52
- impl SpanData {
53
- pub fn from_span ( span : Span , cm : & CodeMap ) -> SpanData {
54
- let start = cm. lookup_char_pos ( span. lo ) ;
55
- let end = cm. lookup_char_pos ( span. hi ) ;
56
-
57
- SpanData {
58
- file_name : start. file . name . clone ( ) ,
59
- byte_start : span. lo . 0 ,
60
- byte_end : span. hi . 0 ,
61
- line_start : start. line ,
62
- line_end : end. line ,
63
- column_start : start. col . 0 + 1 ,
64
- column_end : end. col . 0 + 1 ,
65
- }
43
+ pub fn span_from_span ( span : Span , cm : & CodeMap ) -> SpanData {
44
+ let start = cm. lookup_char_pos ( span. lo ) ;
45
+ let end = cm. lookup_char_pos ( span. hi ) ;
46
+
47
+ SpanData {
48
+ file_name : start. file . name . clone ( ) . into ( ) ,
49
+ byte_start : span. lo . 0 ,
50
+ byte_end : span. hi . 0 ,
51
+ line_start : start. line ,
52
+ line_end : end. line ,
53
+ column_start : start. col . 0 + 1 ,
54
+ column_end : end. col . 0 + 1 ,
66
55
}
67
56
}
68
57
69
58
/// Represent an arbitrary attribute on a code element
70
59
#[ derive( Clone , Debug , RustcEncodable ) ]
71
60
pub struct Attribute {
72
- value : String ,
73
- span : SpanData ,
61
+ pub value : String ,
62
+ pub span : SpanData ,
74
63
}
75
64
76
65
impl Lower for Vec < ast:: Attribute > {
@@ -93,20 +82,12 @@ impl Lower for Vec<ast::Attribute> {
93
82
94
83
Attribute {
95
84
value : value,
96
- span : SpanData :: from_span ( attr. span , tcx. sess . codemap ( ) ) ,
85
+ span : span_from_span ( attr. span , tcx. sess . codemap ( ) ) ,
97
86
}
98
87
} ) . collect ( )
99
88
}
100
89
}
101
90
102
- #[ derive( Debug , RustcEncodable ) ]
103
- pub struct CratePreludeData {
104
- pub crate_name : String ,
105
- pub crate_root : String ,
106
- pub external_crates : Vec < data:: ExternalCrateData > ,
107
- pub span : SpanData ,
108
- }
109
-
110
91
impl Lower for data:: CratePreludeData {
111
92
type Target = CratePreludeData ;
112
93
@@ -115,7 +96,7 @@ impl Lower for data::CratePreludeData {
115
96
crate_name : self . crate_name ,
116
97
crate_root : self . crate_root ,
117
98
external_crates : self . external_crates ,
118
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
99
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
119
100
}
120
101
}
121
102
}
@@ -145,7 +126,7 @@ impl Lower for data::EnumData {
145
126
name : self . name ,
146
127
value : self . value ,
147
128
qualname : self . qualname ,
148
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
129
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
149
130
scope : make_def_id ( self . scope , & tcx. hir ) ,
150
131
variants : self . variants . into_iter ( ) . map ( |id| make_def_id ( id, & tcx. hir ) ) . collect ( ) ,
151
132
visibility : self . visibility ,
@@ -176,7 +157,7 @@ impl Lower for data::ExternCrateData {
176
157
name : self . name ,
177
158
crate_num : self . crate_num ,
178
159
location : self . location ,
179
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
160
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
180
161
scope : make_def_id ( self . scope , & tcx. hir ) ,
181
162
}
182
163
}
@@ -195,7 +176,7 @@ impl Lower for data::FunctionCallData {
195
176
196
177
fn lower ( self , tcx : TyCtxt ) -> FunctionCallData {
197
178
FunctionCallData {
198
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
179
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
199
180
scope : make_def_id ( self . scope , & tcx. hir ) ,
200
181
ref_id : self . ref_id ,
201
182
}
@@ -228,7 +209,7 @@ impl Lower for data::FunctionData {
228
209
name : self . name ,
229
210
qualname : self . qualname ,
230
211
declaration : self . declaration ,
231
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
212
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
232
213
scope : make_def_id ( self . scope , & tcx. hir ) ,
233
214
value : self . value ,
234
215
visibility : self . visibility ,
@@ -253,7 +234,7 @@ impl Lower for data::FunctionRefData {
253
234
254
235
fn lower ( self , tcx : TyCtxt ) -> FunctionRefData {
255
236
FunctionRefData {
256
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
237
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
257
238
scope : make_def_id ( self . scope , & tcx. hir ) ,
258
239
ref_id : self . ref_id ,
259
240
}
@@ -274,7 +255,7 @@ impl Lower for data::ImplData {
274
255
fn lower ( self , tcx : TyCtxt ) -> ImplData {
275
256
ImplData {
276
257
id : make_def_id ( self . id , & tcx. hir ) ,
277
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
258
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
278
259
scope : make_def_id ( self . scope , & tcx. hir ) ,
279
260
trait_ref : self . trait_ref ,
280
261
self_ref : self . self_ref ,
@@ -294,7 +275,7 @@ impl Lower for data::InheritanceData {
294
275
295
276
fn lower ( self , tcx : TyCtxt ) -> InheritanceData {
296
277
InheritanceData {
297
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
278
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
298
279
base_id : self . base_id ,
299
280
deriv_id : make_def_id ( self . deriv_id , & tcx. hir )
300
281
}
@@ -315,7 +296,7 @@ impl Lower for data::MacroData {
315
296
316
297
fn lower ( self , tcx : TyCtxt ) -> MacroData {
317
298
MacroData {
318
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
299
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
319
300
name : self . name ,
320
301
qualname : self . qualname ,
321
302
docs : self . docs ,
@@ -340,10 +321,10 @@ impl Lower for data::MacroUseData {
340
321
341
322
fn lower ( self , tcx : TyCtxt ) -> MacroUseData {
342
323
MacroUseData {
343
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
324
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
344
325
name : self . name ,
345
326
qualname : self . qualname ,
346
- callee_span : SpanData :: from_span ( self . callee_span , tcx. sess . codemap ( ) ) ,
327
+ callee_span : span_from_span ( self . callee_span , tcx. sess . codemap ( ) ) ,
347
328
scope : make_def_id ( self . scope , & tcx. hir ) ,
348
329
}
349
330
}
@@ -363,7 +344,7 @@ impl Lower for data::MethodCallData {
363
344
364
345
fn lower ( self , tcx : TyCtxt ) -> MethodCallData {
365
346
MethodCallData {
366
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
347
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
367
348
scope : make_def_id ( self . scope , & tcx. hir ) ,
368
349
ref_id : self . ref_id ,
369
350
decl_id : self . decl_id ,
@@ -393,7 +374,7 @@ impl Lower for data::MethodData {
393
374
394
375
fn lower ( self , tcx : TyCtxt ) -> MethodData {
395
376
MethodData {
396
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
377
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
397
378
name : self . name ,
398
379
scope : make_def_id ( self . scope , & tcx. hir ) ,
399
380
id : make_def_id ( self . id , & tcx. hir ) ,
@@ -433,7 +414,7 @@ impl Lower for data::ModData {
433
414
id : make_def_id ( self . id , & tcx. hir ) ,
434
415
name : self . name ,
435
416
qualname : self . qualname ,
436
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
417
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
437
418
scope : make_def_id ( self . scope , & tcx. hir ) ,
438
419
filename : self . filename ,
439
420
items : self . items . into_iter ( ) . map ( |id| make_def_id ( id, & tcx. hir ) ) . collect ( ) ,
@@ -459,7 +440,7 @@ impl Lower for data::ModRefData {
459
440
460
441
fn lower ( self , tcx : TyCtxt ) -> ModRefData {
461
442
ModRefData {
462
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
443
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
463
444
scope : make_def_id ( self . scope , & tcx. hir ) ,
464
445
ref_id : self . ref_id ,
465
446
qualname : self . qualname ,
@@ -488,7 +469,7 @@ impl Lower for data::StructData {
488
469
489
470
fn lower ( self , tcx : TyCtxt ) -> StructData {
490
471
StructData {
491
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
472
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
492
473
name : self . name ,
493
474
id : make_def_id ( self . id , & tcx. hir ) ,
494
475
ctor_id : make_def_id ( self . ctor_id , & tcx. hir ) ,
@@ -524,7 +505,7 @@ impl Lower for data::StructVariantData {
524
505
525
506
fn lower ( self , tcx : TyCtxt ) -> StructVariantData {
526
507
StructVariantData {
527
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
508
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
528
509
name : self . name ,
529
510
id : make_def_id ( self . id , & tcx. hir ) ,
530
511
qualname : self . qualname ,
@@ -559,7 +540,7 @@ impl Lower for data::TraitData {
559
540
560
541
fn lower ( self , tcx : TyCtxt ) -> TraitData {
561
542
TraitData {
562
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
543
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
563
544
name : self . name ,
564
545
id : make_def_id ( self . id , & tcx. hir ) ,
565
546
qualname : self . qualname ,
@@ -594,7 +575,7 @@ impl Lower for data::TupleVariantData {
594
575
595
576
fn lower ( self , tcx : TyCtxt ) -> TupleVariantData {
596
577
TupleVariantData {
597
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
578
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
598
579
id : make_def_id ( self . id , & tcx. hir ) ,
599
580
name : self . name ,
600
581
qualname : self . qualname ,
@@ -631,7 +612,7 @@ impl Lower for data::TypeDefData {
631
612
TypeDefData {
632
613
id : make_def_id ( self . id , & tcx. hir ) ,
633
614
name : self . name ,
634
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
615
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
635
616
qualname : self . qualname ,
636
617
value : self . value ,
637
618
visibility : self . visibility ,
@@ -657,7 +638,7 @@ impl Lower for data::TypeRefData {
657
638
658
639
fn lower ( self , tcx : TyCtxt ) -> TypeRefData {
659
640
TypeRefData {
660
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
641
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
661
642
scope : make_def_id ( self . scope , & tcx. hir ) ,
662
643
ref_id : self . ref_id ,
663
644
qualname : self . qualname ,
@@ -681,7 +662,7 @@ impl Lower for data::UseData {
681
662
fn lower ( self , tcx : TyCtxt ) -> UseData {
682
663
UseData {
683
664
id : make_def_id ( self . id , & tcx. hir ) ,
684
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
665
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
685
666
name : self . name ,
686
667
mod_id : self . mod_id ,
687
668
scope : make_def_id ( self . scope , & tcx. hir ) ,
@@ -705,7 +686,7 @@ impl Lower for data::UseGlobData {
705
686
fn lower ( self , tcx : TyCtxt ) -> UseGlobData {
706
687
UseGlobData {
707
688
id : make_def_id ( self . id , & tcx. hir ) ,
708
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
689
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
709
690
names : self . names ,
710
691
scope : make_def_id ( self . scope , & tcx. hir ) ,
711
692
visibility : self . visibility ,
@@ -740,7 +721,7 @@ impl Lower for data::VariableData {
740
721
kind : self . kind ,
741
722
name : self . name ,
742
723
qualname : self . qualname ,
743
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
724
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
744
725
scope : make_def_id ( self . scope , & tcx. hir ) ,
745
726
value : self . value ,
746
727
type_value : self . type_value ,
@@ -769,7 +750,7 @@ impl Lower for data::VariableRefData {
769
750
fn lower ( self , tcx : TyCtxt ) -> VariableRefData {
770
751
VariableRefData {
771
752
name : self . name ,
772
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
753
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
773
754
scope : make_def_id ( self . scope , & tcx. hir ) ,
774
755
ref_id : self . ref_id ,
775
756
}
@@ -793,7 +774,7 @@ impl Lower for data::Signature {
793
774
794
775
fn lower ( self , tcx : TyCtxt ) -> Signature {
795
776
Signature {
796
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
777
+ span : span_from_span ( self . span , tcx. sess . codemap ( ) ) ,
797
778
text : self . text ,
798
779
ident_start : self . ident_start ,
799
780
ident_end : self . ident_end ,
0 commit comments