11use {
22 crate :: {
33 abi:: { self , MAX_FLAT_PARAMS , MAX_FLAT_RESULTS } ,
4- bindgen:: DISPATCHABLE_CORE_PARAM_COUNT ,
4+ bindgen:: { self , DISPATCHABLE_CORE_PARAM_COUNT } ,
55 exports:: exports:: {
66 self , Case , Constructor , Function , FunctionExport , LocalResource , OwnedKind , OwnedType ,
77 RemoteResource , Resource , Static , Symbols ,
@@ -700,6 +700,8 @@ impl<'a> Summary<'a> {
700700
701701 fn function_code (
702702 & self ,
703+ direction : Direction ,
704+ world_module : & str ,
703705 function : & MyFunction ,
704706 names : & mut TypeNames ,
705707 seen : & HashSet < TypeId > ,
@@ -733,6 +735,27 @@ impl<'a> Summary<'a> {
733735
734736 let mut type_name = |ty| names. type_name ( ty, seen, if self_ { resource } else { None } ) ;
735737
738+ let absolute_type_name = |ty| {
739+ format ! (
740+ "{world_module}.{}.{}" ,
741+ match direction {
742+ Direction :: Import => "imports" ,
743+ Direction :: Export => "exports" ,
744+ } ,
745+ TypeNames :: new( self , TypeOwner :: None ) . type_name(
746+ ty,
747+ & if let Type :: Id ( id) = ty {
748+ Some ( bindgen:: dealias( self . resolve, id) )
749+ } else {
750+ None
751+ }
752+ . into_iter( )
753+ . collect:: <HashSet <_>>( ) ,
754+ None
755+ )
756+ )
757+ } ;
758+
736759 let params = self_
737760 . then ( || "self" . to_string ( ) )
738761 . into_iter ( )
@@ -767,7 +790,7 @@ impl<'a> Summary<'a> {
767790 [ ty] => match special_return ( * ty) {
768791 SpecialReturn :: Result ( result) => {
769792 let error = if let Some ( ty) = result. err {
770- Some ( type_name ( ty) )
793+ Some ( absolute_type_name ( ty) )
771794 } else {
772795 Some ( "None" . into ( ) )
773796 } ;
@@ -944,7 +967,12 @@ impl<'a> Summary<'a> {
944967 sorted
945968 }
946969
947- pub fn generate_code ( & self , path : & Path , stub_runtime_calls : bool ) -> Result < ( ) > {
970+ pub fn generate_code (
971+ & self ,
972+ path : & Path ,
973+ world_module : & str ,
974+ stub_runtime_calls : bool ,
975+ ) -> Result < ( ) > {
948976 #[ derive( Default ) ]
949977 struct Definitions < ' a > {
950978 types : Vec < String > ,
@@ -964,7 +992,10 @@ impl<'a> Summary<'a> {
964992 }
965993
966994 let docstring = |docs : Option < & str > , indent_level, error : Option < & str > | {
967- let docs = match ( docs, error. map ( |e| format ! ( "Raises: Err({e})" ) ) ) {
995+ let docs = match (
996+ docs,
997+ error. map ( |e| format ! ( "Raises: `{world_module}.types.Err({e})`" ) ) ,
998+ ) {
968999 ( Some ( docs) , Some ( error_docs) ) => Some ( format ! ( "{docs}\n \n {error_docs}" ) ) ,
9691000 ( Some ( docs) , None ) => Some ( docs. to_owned ( ) ) ,
9701001 ( None , Some ( error_docs) ) => Some ( error_docs) ,
@@ -1070,20 +1101,14 @@ class {name}:
10701101 . collect :: < Vec < _ > > ( )
10711102 . join ( ", " ) ;
10721103
1073- let docs = if let Some ( docs) = & ty. docs . contents {
1074- docs. lines ( )
1075- . map ( |line| format ! ( "# {line}\n " ) )
1076- . collect :: < Vec < _ > > ( )
1077- . concat ( )
1078- } else {
1079- String :: new ( )
1080- } ;
1104+ let docs = docstring ( ty. docs . contents . as_deref ( ) , 0 , None ) ;
10811105
10821106 Code :: Shared ( format ! (
10831107 "
10841108{classes}
10851109
1086- {docs}{camel} = Union[{cases}]
1110+ {camel} = Union[{cases}]
1111+ {docs}
10871112"
10881113 ) )
10891114 }
@@ -1156,7 +1181,14 @@ class {camel}(Flag):
11561181 static_method,
11571182 result_count,
11581183 error,
1159- } = self . function_code ( function, & mut names, & seen, Some ( id) ) ;
1184+ } = self . function_code (
1185+ Direction :: Import ,
1186+ world_module,
1187+ function,
1188+ & mut names,
1189+ & seen,
1190+ Some ( id) ,
1191+ ) ;
11601192
11611193 let docs = docstring ( function. docs , 2 , error. as_deref ( ) ) ;
11621194
@@ -1271,7 +1303,14 @@ class {camel}:
12711303 static_method,
12721304 error,
12731305 ..
1274- } = self . function_code ( function, & mut names, & seen, Some ( id) ) ;
1306+ } = self . function_code (
1307+ Direction :: Export ,
1308+ world_module,
1309+ function,
1310+ & mut names,
1311+ & seen,
1312+ Some ( id) ,
1313+ ) ;
12751314
12761315 let docs = docstring ( function. docs , 2 , error. as_deref ( ) ) ;
12771316
@@ -1419,7 +1458,14 @@ class {camel}(Protocol):
14191458 result_count,
14201459 error,
14211460 ..
1422- } = self . function_code ( function, & mut names, & seen, None ) ;
1461+ } = self . function_code (
1462+ Direction :: Import ,
1463+ world_module,
1464+ function,
1465+ & mut names,
1466+ & seen,
1467+ None ,
1468+ ) ;
14231469
14241470 match function. kind {
14251471 FunctionKind :: Import => {
0 commit comments