@@ -6,14 +6,16 @@ use std::convert::From;
66
77use rustc_ast:: ast;
88use rustc_span:: def_id:: { DefId , CRATE_DEF_INDEX } ;
9+ use rustc_span:: Pos ;
910
1011use crate :: clean;
1112use crate :: doctree;
1213use crate :: formats:: item_type:: ItemType ;
1314use crate :: json:: types:: * ;
15+ use crate :: json:: JsonRenderer ;
1416
15- impl From < clean :: Item > for Option < Item > {
16- fn from ( item : clean:: Item ) -> Self {
17+ impl JsonRenderer {
18+ pub ( super ) fn convert_item ( & self , item : clean:: Item ) -> Option < Item > {
1719 let item_type = ItemType :: from ( & item) ;
1820 let clean:: Item {
1921 source,
@@ -32,7 +34,7 @@ impl From<clean::Item> for Option<Item> {
3234 id : def_id. into ( ) ,
3335 crate_id : def_id. krate . as_u32 ( ) ,
3436 name,
35- source : source . into ( ) ,
37+ source : self . convert_span ( source ) ,
3638 visibility : visibility. into ( ) ,
3739 docs : attrs. collapsed_doc_value ( ) . unwrap_or_default ( ) ,
3840 links : attrs
@@ -53,25 +55,23 @@ impl From<clean::Item> for Option<Item> {
5355 } ) ,
5456 }
5557 }
56- }
5758
58- impl From < clean:: Span > for Option < Span > {
59- #[ allow( unreachable_code) ]
60- fn from ( span : clean:: Span ) -> Self {
61- // TODO: this should actually work
62- // Unfortunately this requires rethinking the whole framework,
63- // since this now needs a context and not just .into().
64- match span. filename ( todo ! ( ) ) {
65- rustc_span:: FileName :: Real ( name) => Some ( Span {
66- filename : match name {
67- rustc_span:: RealFileName :: Named ( path) => path,
68- rustc_span:: RealFileName :: Devirtualized { local_path, virtual_name : _ } => {
69- local_path
70- }
71- } ,
72- begin : todo ! ( ) ,
73- end : todo ! ( ) ,
74- } ) ,
59+ fn convert_span ( & self , span : clean:: Span ) -> Option < Span > {
60+ match span. filename ( & self . sess ) {
61+ rustc_span:: FileName :: Real ( name) => {
62+ let hi = span. hi ( & self . sess ) ;
63+ let lo = span. lo ( & self . sess ) ;
64+ Some ( Span {
65+ filename : match name {
66+ rustc_span:: RealFileName :: Named ( path) => path,
67+ rustc_span:: RealFileName :: Devirtualized { local_path, virtual_name : _ } => {
68+ local_path
69+ }
70+ } ,
71+ begin : ( lo. line , lo. col . to_usize ( ) ) ,
72+ end : ( hi. line , hi. col . to_usize ( ) ) ,
73+ } )
74+ }
7575 _ => None ,
7676 }
7777 }
0 commit comments