@@ -32,6 +32,7 @@ pub struct CrateTranslator<'a> {
3232 krate : & ' a Crate ,
3333 vfs : & ' a Vfs ,
3434 archiver : & ' a Archiver ,
35+ extract_dependencies : bool ,
3536 file_labels : HashMap < PathBuf , FileData > ,
3637}
3738
@@ -42,13 +43,15 @@ impl CrateTranslator<'_> {
4243 krate : & ' a Crate ,
4344 vfs : & ' a Vfs ,
4445 archiver : & ' a Archiver ,
46+ extract_dependencies : bool ,
4547 ) -> CrateTranslator < ' a > {
4648 CrateTranslator {
4749 db,
4850 trap,
4951 krate,
5052 vfs,
5153 archiver,
54+ extract_dependencies,
5255 file_labels : HashMap :: new ( ) ,
5356 }
5457 }
@@ -928,20 +931,27 @@ impl CrateTranslator<'_> {
928931 }
929932 ModuleDef :: Function ( function) => {
930933 let def: ra_ap_hir:: DefWithBody = function. into ( ) ;
931- let ( body, source_map) = self . db . body_with_source_map ( def. into ( ) ) ;
932- let txt = body. pretty_print ( self . db , def. into ( ) , Edition :: Edition2021 ) ;
933- println ! ( "{}" , & txt) ;
934934
935935 let name = function. name ( self . db ) ;
936-
937936 let location = self . emit_location ( function) ;
938- let body = self . emit_expr ( body. body_expr , & body, & source_map) ;
937+
938+ let body = if self . extract_dependencies || self . krate . origin ( self . db ) . is_local ( ) {
939+ let ( body, source_map) = self . db . body_with_source_map ( def. into ( ) ) ;
940+ let txt = body. pretty_print ( self . db , def. into ( ) , Edition :: Edition2021 ) ;
941+ println ! ( "{}" , & txt) ;
942+ self . emit_expr ( body. body_expr , & body, & source_map)
943+ } else {
944+ self . trap . emit ( generated:: MissingExpr {
945+ id : TrapId :: Star ,
946+ location : None ,
947+ } )
948+ } ;
939949 labels. push ( self . trap . emit ( generated:: Function {
940950 id : trap_key ! [ module_label, name. as_str( ) ] ,
941951 location,
942952 name : name. as_str ( ) . into ( ) ,
943953 body,
944- } ) ) ;
954+ } ) )
945955 }
946956 ModuleDef :: Adt ( adt) => {
947957 let location = self . emit_location ( adt) ;
0 commit comments