11use crate :: traits:: Trait ;
2- use crate :: util:: make_path;
2+ use crate :: util:: { make_path, wit_func_name } ;
33use heck:: { ToKebabCase , ToSnakeCase } ;
44use quote:: quote;
55use syn:: { Item , ItemEnum , ItemStruct , parse_quote} ;
@@ -80,25 +80,32 @@ impl Trait for DialogTrait {
8080 fn struct_trait ( & self , module_path : & [ String ] , struct_item : & ItemStruct ) -> Vec < Item > {
8181 let mut res = Vec :: new ( ) ;
8282 let struct_name = make_path ( module_path, & struct_item. ident . to_string ( ) ) ;
83+ let struct_wit_name = wit_func_name ( module_path, & None , & struct_item. ident , & None ) ;
8384 let ( impl_generics, ty_generics, where_clause) = struct_item. generics . split_for_impl ( ) ;
84- let ( field_names, tys) = match & struct_item. fields {
85- syn:: Fields :: Unit => ( Vec :: new ( ) , Vec :: new ( ) ) ,
85+ let ( field_names, tys, field_wit_names ) = match & struct_item. fields {
86+ syn:: Fields :: Unit => ( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ,
8687 syn:: Fields :: Named ( fields) => {
8788 let field_names: Vec < _ > = fields
8889 . named
8990 . iter ( )
9091 . map ( |f| f. ident . clone ( ) . unwrap ( ) )
9192 . collect ( ) ;
9293 let field_tys = fields. named . iter ( ) . map ( |f| & f. ty ) . collect ( ) ;
93- ( field_names, field_tys)
94+ let field_wit_names = fields
95+ . named
96+ . iter ( )
97+ . map ( |f| f. ident . clone ( ) . unwrap ( ) . to_string ( ) . to_kebab_case ( ) )
98+ . collect ( ) ;
99+ ( field_names, field_tys, field_wit_names)
94100 }
95101 syn:: Fields :: Unnamed ( _) => unreachable ! ( ) ,
96102 } ;
97103 res. push ( parse_quote ! {
98104 impl #impl_generics Dialog for #struct_name #ty_generics #where_clause {
99105 fn read_value( dep: u32 ) -> Self {
106+ proxy:: util:: dialog:: print( dep, & format!( "provide value for struct {}" , #struct_wit_name) ) ;
100107 #(
101- proxy:: util:: dialog:: print( dep + 1 , & format!( "provide value for field {}: {:60}" , stringify! ( #field_names ) , <#tys as ValueTyped >:: value_type( ) . to_string( ) ) ) ;
108+ proxy:: util:: dialog:: print( dep + 1 , & format!( "provide value for field {}: {:. 60}" , #field_wit_names , <#tys as ValueTyped >:: value_type( ) . to_string( ) ) ) ;
102109 let #field_names = Dialog :: read_value( dep + 1 ) ;
103110 ) *
104111 Self {
@@ -117,7 +124,7 @@ impl Trait for DialogTrait {
117124 let ( impl_generics, ty_generics, where_clause) = enum_item. generics . split_for_impl ( ) ;
118125 let tags = enum_item. variants . iter ( ) . map ( |variant| {
119126 let tag = & variant. ident ;
120- quote ! { stringify! ( # tag) }
127+ tag. to_string ( ) . to_kebab_case ( )
121128 } ) ;
122129 let tags = quote ! { [ #( #tags. to_string( ) ) , * ] } ;
123130 let arms = enum_item. variants . iter ( ) . enumerate ( ) . map ( |( idx, variant) | {
@@ -132,10 +139,11 @@ impl Trait for DialogTrait {
132139 syn:: Fields :: Named ( _) => unreachable ! ( ) ,
133140 }
134141 } ) ;
142+ let enum_wit_name = wit_func_name ( module_path, & None , & enum_item. ident , & None ) ;
135143 res. push ( parse_quote ! {
136144 impl #impl_generics Dialog for #enum_name #ty_generics #where_clause {
137145 fn read_value( dep: u32 ) -> Self {
138- let idx = proxy:: util:: dialog:: read_select( dep, & format!( "Select a variant for {}" , stringify! ( #enum_name ) ) , & #tags) as usize ;
146+ let idx = proxy:: util:: dialog:: read_select( dep, & format!( "Select a variant for {}" , #enum_wit_name ) , & #tags) as usize ;
139147 match idx {
140148 #(
141149 #arms,
@@ -150,14 +158,19 @@ impl Trait for DialogTrait {
150158 fn flag_trait ( & self , module_path : & [ String ] , item : & crate :: codegen:: ItemFlag ) -> Vec < Item > {
151159 let mut res = Vec :: new ( ) ;
152160 let flag_path = make_path ( module_path, & item. name . to_string ( ) ) ;
161+ let flag_wit_name = wit_func_name ( module_path, & None , & item. name , & None ) ;
153162 let flags = & item. flags ;
154- let flag_names = quote ! { [ #( stringify!( #flags) . to_string( ) ) , * ] } ;
163+ let flag_names: Vec < _ > = flags
164+ . iter ( )
165+ . map ( |flag| flag. to_string ( ) . to_kebab_case ( ) )
166+ . collect ( ) ;
167+ let flag_names = quote ! { [ #( #flag_names. to_string( ) ) , * ] } ;
155168 let flags = flags. iter ( ) . map ( |flag| quote ! { #flag_path:: #flag } ) ;
156169 let idxs = 0 ..flags. len ( ) ;
157170 res. push ( parse_quote ! {
158171 impl Dialog for #flag_path {
159172 fn read_value( dep: u32 ) -> Self {
160- let selections = proxy:: util:: dialog:: read_multi_select( dep, & format!( "Select flags for {}" , stringify! ( #flag_path ) ) , & #flag_names) ;
173+ let selections = proxy:: util:: dialog:: read_multi_select( dep, & format!( "Select flags for {}" , #flag_wit_name ) , & #flag_names) ;
161174 let mut res = #flag_path:: empty( ) ;
162175 for idx in selections {
163176 match idx as usize {
@@ -188,7 +201,7 @@ impl Trait for DialogTrait {
188201 }
189202 impl <T : Dialog > Dialog for Option <T > {
190203 fn read_value( dep: u32 ) -> Self {
191- let selection = proxy:: util:: dialog:: read_select( dep, "Select None or Some " , & [ "None " . to_string( ) , "Some " . to_string( ) ] ) ;
204+ let selection = proxy:: util:: dialog:: read_select( dep, "Select an option tag " , & [ "none " . to_string( ) , "some " . to_string( ) ] ) ;
192205 if selection == 0 {
193206 None
194207 } else {
0 commit comments