@@ -175,8 +175,7 @@ fn add_func_to_accumulator(
175
175
edit. edit_file ( file) ;
176
176
177
177
let target = function_builder. target . clone ( ) ;
178
- let function_template = function_builder. render ( ) ;
179
- let func = function_template. to_ast ( ctx. config . snippet_cap , edit) ;
178
+ let func = function_builder. render ( ctx. config . snippet_cap , edit) ;
180
179
181
180
if let Some ( name) = adt_name {
182
181
let name = make:: ty_path ( make:: ext:: ident_path ( & format ! ( "{}" , name. display( ctx. db( ) ) ) ) ) ;
@@ -205,37 +204,6 @@ fn get_adt_source(
205
204
find_struct_impl ( ctx, & adt_source, & [ fn_name. to_owned ( ) ] ) . map ( |impl_| ( impl_, range. file_id ) )
206
205
}
207
206
208
- struct FunctionTemplate {
209
- fn_def : ast:: Fn ,
210
- ret_type : Option < ast:: RetType > ,
211
- should_focus_return_type : bool ,
212
- tail_expr : ast:: Expr ,
213
- }
214
-
215
- impl FunctionTemplate {
216
- fn to_ast ( & self , cap : Option < SnippetCap > , edit : & mut SourceChangeBuilder ) -> ast:: Fn {
217
- let Self { fn_def, ret_type, should_focus_return_type, tail_expr } = self ;
218
-
219
- if let Some ( cap) = cap {
220
- if * should_focus_return_type {
221
- // Focus the return type if there is one
222
- match ret_type {
223
- Some ( ret_type) => {
224
- edit. add_placeholder_snippet ( cap, ret_type. clone ( ) ) ;
225
- }
226
- None => {
227
- edit. add_placeholder_snippet ( cap, tail_expr. clone ( ) ) ;
228
- }
229
- }
230
- } else {
231
- edit. add_placeholder_snippet ( cap, tail_expr. clone ( ) ) ;
232
- }
233
- }
234
-
235
- fn_def. clone ( )
236
- }
237
- }
238
-
239
207
struct FunctionBuilder {
240
208
target : GeneratedFunctionTarget ,
241
209
fn_name : ast:: Name ,
@@ -339,7 +307,7 @@ impl FunctionBuilder {
339
307
} )
340
308
}
341
309
342
- fn render ( self ) -> FunctionTemplate {
310
+ fn render ( self , cap : Option < SnippetCap > , edit : & mut SourceChangeBuilder ) -> ast :: Fn {
343
311
let placeholder_expr = make:: ext:: expr_todo ( ) ;
344
312
let fn_body = make:: block_expr ( vec ! [ ] , Some ( placeholder_expr) ) ;
345
313
let visibility = match self . visibility {
@@ -361,17 +329,31 @@ impl FunctionBuilder {
361
329
)
362
330
. clone_for_update ( ) ;
363
331
364
- FunctionTemplate {
365
- ret_type : fn_def. ret_type ( ) ,
366
- // PANIC: we guarantee we always create a function body with a tail expr
367
- tail_expr : fn_def
368
- . body ( )
369
- . expect ( "generated function should have a body" )
370
- . tail_expr ( )
371
- . expect ( "function body should have a tail expression" ) ,
372
- should_focus_return_type : self . should_focus_return_type ,
373
- fn_def,
332
+ let ret_type = fn_def. ret_type ( ) ;
333
+ // PANIC: we guarantee we always create a function body with a tail expr
334
+ let tail_expr = fn_def
335
+ . body ( )
336
+ . expect ( "generated function should have a body" )
337
+ . tail_expr ( )
338
+ . expect ( "function body should have a tail expression" ) ;
339
+
340
+ if let Some ( cap) = cap {
341
+ if self . should_focus_return_type {
342
+ // Focus the return type if there is one
343
+ match ret_type {
344
+ Some ( ret_type) => {
345
+ edit. add_placeholder_snippet ( cap, ret_type. clone ( ) ) ;
346
+ }
347
+ None => {
348
+ edit. add_placeholder_snippet ( cap, tail_expr. clone ( ) ) ;
349
+ }
350
+ }
351
+ } else {
352
+ edit. add_placeholder_snippet ( cap, tail_expr. clone ( ) ) ;
353
+ }
374
354
}
355
+
356
+ fn_def
375
357
}
376
358
}
377
359
0 commit comments