@@ -107,31 +107,48 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
107
107
|edit| {
108
108
// Create the function
109
109
let method_source = match ctx. sema . source ( method) {
110
- Some ( source) => source. value ,
110
+ Some ( source) => {
111
+ let v = source. value . clone_for_update ( ) ;
112
+ let source_scope = ctx. sema . scope ( v. syntax ( ) ) ;
113
+ let target_scope = ctx. sema . scope ( strukt. syntax ( ) ) ;
114
+ if let ( Some ( s) , Some ( t) ) = ( source_scope, target_scope) {
115
+ PathTransform :: generic_transformation ( & t, & s) . apply ( v. syntax ( ) ) ;
116
+ }
117
+ v
118
+ }
111
119
None => return ,
112
120
} ;
121
+
113
122
let vis = method_source. visibility ( ) ;
123
+ let is_async = method_source. async_token ( ) . is_some ( ) ;
124
+ let is_const = method_source. const_token ( ) . is_some ( ) ;
125
+ let is_unsafe = method_source. unsafe_token ( ) . is_some ( ) ;
126
+
114
127
let fn_name = make:: name ( & name) ;
128
+
129
+ let type_params = method_source. generic_param_list ( ) ;
130
+ let where_clause = method_source. where_clause ( ) ;
115
131
let params =
116
132
method_source. param_list ( ) . unwrap_or_else ( || make:: param_list ( None , [ ] ) ) ;
117
- let type_params = method_source. generic_param_list ( ) ;
118
- let arg_list = match method_source. param_list ( ) {
119
- Some ( list) => convert_param_list_to_arg_list ( list) ,
120
- None => make:: arg_list ( [ ] ) ,
121
- } ;
133
+
134
+ // compute the `body`
135
+ let arg_list = method_source
136
+ . param_list ( )
137
+ . map ( |list| convert_param_list_to_arg_list ( list) )
138
+ . unwrap_or_else ( || make:: arg_list ( [ ] ) ) ;
139
+
122
140
let tail_expr = make:: expr_method_call ( field, make:: name_ref ( & name) , arg_list) ;
123
- let ret_type = method_source. ret_type ( ) ;
124
- let is_async = method_source. async_token ( ) . is_some ( ) ;
125
- let is_const = method_source. const_token ( ) . is_some ( ) ;
126
- let is_unsafe = method_source. unsafe_token ( ) . is_some ( ) ;
127
141
let tail_expr_finished =
128
142
if is_async { make:: expr_await ( tail_expr) } else { tail_expr } ;
129
143
let body = make:: block_expr ( [ ] , Some ( tail_expr_finished) ) ;
144
+
145
+ let ret_type = method_source. ret_type ( ) ;
146
+
130
147
let f = make:: fn_ (
131
148
vis,
132
149
fn_name,
133
150
type_params,
134
- method_source . where_clause ( ) ,
151
+ where_clause,
135
152
params,
136
153
body,
137
154
ret_type,
@@ -184,12 +201,6 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
184
201
let assoc_items = impl_def. get_or_create_assoc_item_list ( ) ;
185
202
assoc_items. add_item ( f. clone ( ) . into ( ) ) ;
186
203
187
- if let Some ( ( target, source) ) =
188
- ctx. sema . scope ( strukt. syntax ( ) ) . zip ( ctx. sema . scope ( method_source. syntax ( ) ) )
189
- {
190
- PathTransform :: generic_transformation ( & target, & source) . apply ( f. syntax ( ) ) ;
191
- }
192
-
193
204
if let Some ( cap) = ctx. config . snippet_cap {
194
205
edit. add_tabstop_before ( cap, f)
195
206
}
0 commit comments