@@ -45,6 +45,7 @@ use rustc::session::config::CrateType::CrateTypeExecutable;
4545use rustc:: ty:: { self , TyCtxt } ;
4646use rustc_typeck:: hir_ty_to_ty;
4747
48+ use std:: cell:: Cell ;
4849use std:: default:: Default ;
4950use std:: env;
5051use std:: fs:: File ;
@@ -65,7 +66,7 @@ use dump_visitor::DumpVisitor;
6566use span_utils:: SpanUtils ;
6667
6768use rls_data:: { Def , DefKind , ExternalCrateData , GlobalCrateId , MacroRef , Ref , RefKind , Relation ,
68- RelationKind , SpanData } ;
69+ RelationKind , SpanData , Impl , ImplKind } ;
6970use rls_data:: config:: Config ;
7071
7172
@@ -75,13 +76,14 @@ pub struct SaveContext<'l, 'tcx: 'l> {
7576 analysis : & ' l ty:: CrateAnalysis ,
7677 span_utils : SpanUtils < ' tcx > ,
7778 config : Config ,
79+ impl_counter : Cell < u32 > ,
7880}
7981
8082#[ derive( Debug ) ]
8183pub enum Data {
8284 RefData ( Ref ) ,
8385 DefData ( Def ) ,
84- RelationData ( Relation ) ,
86+ RelationData ( Relation , Impl ) ,
8587}
8688
8789impl < ' l , ' tcx : ' l > SaveContext < ' l , ' tcx > {
@@ -315,7 +317,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
315317 attributes : lower_attributes ( item. attrs . to_owned ( ) , self ) ,
316318 } ) )
317319 }
318- ast:: ItemKind :: Impl ( .., ref trait_ref, ref typ, _ ) => {
320+ ast:: ItemKind :: Impl ( .., ref trait_ref, ref typ, ref impls ) => {
319321 if let ast:: TyKind :: Path ( None , ref path) = typ. node {
320322 // Common case impl for a struct or something basic.
321323 if generated_code ( path. span ) {
@@ -324,17 +326,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
324326 let sub_span = self . span_utils . sub_span_for_type_name ( path. span ) ;
325327 filter ! ( self . span_utils, sub_span, typ. span, None ) ;
326328
329+ let impl_id = self . next_impl_id ( ) ;
330+ let span = self . span_from_span ( sub_span. unwrap ( ) ) ;
331+
327332 let type_data = self . lookup_ref_id ( typ. id ) ;
328333 type_data. map ( |type_data| {
329334 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 ( ) ,
332339 from : id_from_def_id ( type_data) ,
333340 to : trait_ref
334341 . as_ref ( )
335342 . and_then ( |t| self . lookup_ref_id ( t. ref_id ) )
336343 . map ( id_from_def_id)
337344 . 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 ! [ ] ,
338362 } )
339363 } )
340364 } else {
@@ -893,6 +917,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
893917
894918 result
895919 }
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+ }
896926}
897927
898928fn make_signature ( decl : & ast:: FnDecl , generics : & ast:: Generics ) -> String {
@@ -1099,6 +1129,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
10991129 analysis,
11001130 span_utils : SpanUtils :: new ( & tcx. sess ) ,
11011131 config : find_config ( config) ,
1132+ impl_counter : Cell :: new ( 0 ) ,
11021133 } ;
11031134
11041135 handler. save ( save_ctxt, krate, cratename)
0 commit comments