@@ -45,6 +45,7 @@ use rustc::session::config::CrateType::CrateTypeExecutable;
45
45
use rustc:: ty:: { self , TyCtxt } ;
46
46
use rustc_typeck:: hir_ty_to_ty;
47
47
48
+ use std:: cell:: Cell ;
48
49
use std:: default:: Default ;
49
50
use std:: env;
50
51
use std:: fs:: File ;
@@ -65,7 +66,7 @@ use dump_visitor::DumpVisitor;
65
66
use span_utils:: SpanUtils ;
66
67
67
68
use rls_data:: { Def , DefKind , ExternalCrateData , GlobalCrateId , MacroRef , Ref , RefKind , Relation ,
68
- RelationKind , SpanData } ;
69
+ RelationKind , SpanData , Impl , ImplKind } ;
69
70
use rls_data:: config:: Config ;
70
71
71
72
@@ -75,13 +76,14 @@ pub struct SaveContext<'l, 'tcx: 'l> {
75
76
analysis : & ' l ty:: CrateAnalysis ,
76
77
span_utils : SpanUtils < ' tcx > ,
77
78
config : Config ,
79
+ impl_counter : Cell < u32 > ,
78
80
}
79
81
80
82
#[ derive( Debug ) ]
81
83
pub enum Data {
82
84
RefData ( Ref ) ,
83
85
DefData ( Def ) ,
84
- RelationData ( Relation ) ,
86
+ RelationData ( Relation , Impl ) ,
85
87
}
86
88
87
89
impl < ' l , ' tcx : ' l > SaveContext < ' l , ' tcx > {
@@ -315,7 +317,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
315
317
attributes : lower_attributes ( item. attrs . to_owned ( ) , self ) ,
316
318
} ) )
317
319
}
318
- ast:: ItemKind :: Impl ( .., ref trait_ref, ref typ, _ ) => {
320
+ ast:: ItemKind :: Impl ( .., ref trait_ref, ref typ, ref impls ) => {
319
321
if let ast:: TyKind :: Path ( None , ref path) = typ. node {
320
322
// Common case impl for a struct or something basic.
321
323
if generated_code ( path. span ) {
@@ -324,17 +326,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
324
326
let sub_span = self . span_utils . sub_span_for_type_name ( path. span ) ;
325
327
filter ! ( self . span_utils, sub_span, typ. span, None ) ;
326
328
329
+ let impl_id = self . next_impl_id ( ) ;
330
+ let span = self . span_from_span ( sub_span. unwrap ( ) ) ;
331
+
327
332
let type_data = self . lookup_ref_id ( typ. id ) ;
328
333
type_data. map ( |type_data| {
329
334
Data :: RelationData ( Relation {
330
- kind : RelationKind :: Impl ,
331
- span : self . span_from_span ( sub_span. unwrap ( ) ) ,
335
+ kind : RelationKind :: Impl {
336
+ id : impl_id,
337
+ } ,
338
+ span : span. clone ( ) ,
332
339
from : id_from_def_id ( type_data) ,
333
340
to : trait_ref
334
341
. as_ref ( )
335
342
. and_then ( |t| self . lookup_ref_id ( t. ref_id ) )
336
343
. map ( id_from_def_id)
337
344
. unwrap_or ( null_id ( ) ) ,
345
+ } ,
346
+ Impl {
347
+ id : impl_id,
348
+ kind : match * trait_ref {
349
+ Some ( _) => ImplKind :: Direct ,
350
+ None => ImplKind :: Inherent ,
351
+ } ,
352
+ span : span,
353
+ value : String :: new ( ) ,
354
+ parent : None ,
355
+ children : impls
356
+ . iter ( )
357
+ . map ( |i| id_from_node_id ( i. id , self ) )
358
+ . collect ( ) ,
359
+ docs : String :: new ( ) ,
360
+ sig : None ,
361
+ attributes : vec ! [ ] ,
338
362
} )
339
363
} )
340
364
} else {
@@ -893,6 +917,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
893
917
894
918
result
895
919
}
920
+
921
+ fn next_impl_id ( & self ) -> u32 {
922
+ let next = self . impl_counter . get ( ) ;
923
+ self . impl_counter . set ( next + 1 ) ;
924
+ next
925
+ }
896
926
}
897
927
898
928
fn make_signature ( decl : & ast:: FnDecl , generics : & ast:: Generics ) -> String {
@@ -1099,6 +1129,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
1099
1129
analysis,
1100
1130
span_utils : SpanUtils :: new ( & tcx. sess ) ,
1101
1131
config : find_config ( config) ,
1132
+ impl_counter : Cell :: new ( 0 ) ,
1102
1133
} ;
1103
1134
1104
1135
handler. save ( save_ctxt, krate, cratename)
0 commit comments