@@ -29,6 +29,13 @@ impl<'a> FuncExpr<'a> {
29
29
FuncExpr :: Method ( m_call) => m_call. arg_list ( ) ,
30
30
}
31
31
}
32
+
33
+ fn syntax ( & self ) -> & SyntaxNode {
34
+ match * self {
35
+ FuncExpr :: Func ( fn_call) => fn_call. syntax ( ) ,
36
+ FuncExpr :: Method ( m_call) => m_call. syntax ( ) ,
37
+ }
38
+ }
32
39
}
33
40
34
41
// Assist: generate_function
@@ -173,7 +180,7 @@ impl FunctionBuilder {
173
180
file = in_file;
174
181
target
175
182
}
176
- None => next_space_for_fn_after_call_site ( call) ?,
183
+ None => next_space_for_fn_after_call_site ( FuncExpr :: Func ( call) ) ?,
177
184
} ;
178
185
let needs_pub = target_module. is_some ( ) ;
179
186
let target_module = target_module. or_else ( || ctx. sema . scope ( target. syntax ( ) ) . module ( ) ) ?;
@@ -238,7 +245,7 @@ impl FunctionBuilder {
238
245
file = in_file;
239
246
target
240
247
}
241
- None => next_space_for_fn_after_method_call_site ( call) ?,
248
+ None => next_space_for_fn_after_call_site ( FuncExpr :: Method ( call) ) ?,
242
249
} ;
243
250
let needs_pub = false ;
244
251
let target_module = target_module. or_else ( || ctx. sema . scope ( target. syntax ( ) ) . module ( ) ) ?;
@@ -465,29 +472,7 @@ fn fn_arg_type(
465
472
/// directly after the current block
466
473
/// We want to write the generated function directly after
467
474
/// fns, impls or macro calls, but inside mods
468
- fn next_space_for_fn_after_call_site ( expr : & ast:: CallExpr ) -> Option < GeneratedFunctionTarget > {
469
- let mut ancestors = expr. syntax ( ) . ancestors ( ) . peekable ( ) ;
470
- let mut last_ancestor: Option < SyntaxNode > = None ;
471
- while let Some ( next_ancestor) = ancestors. next ( ) {
472
- match next_ancestor. kind ( ) {
473
- SyntaxKind :: SOURCE_FILE => {
474
- break ;
475
- }
476
- SyntaxKind :: ITEM_LIST => {
477
- if ancestors. peek ( ) . map ( |a| a. kind ( ) ) == Some ( SyntaxKind :: MODULE ) {
478
- break ;
479
- }
480
- }
481
- _ => { }
482
- }
483
- last_ancestor = Some ( next_ancestor) ;
484
- }
485
- last_ancestor. map ( GeneratedFunctionTarget :: BehindItem )
486
- }
487
-
488
- fn next_space_for_fn_after_method_call_site (
489
- expr : & ast:: MethodCallExpr ,
490
- ) -> Option < GeneratedFunctionTarget > {
475
+ fn next_space_for_fn_after_call_site ( expr : FuncExpr ) -> Option < GeneratedFunctionTarget > {
491
476
let mut ancestors = expr. syntax ( ) . ancestors ( ) . peekable ( ) ;
492
477
let mut last_ancestor: Option < SyntaxNode > = None ;
493
478
while let Some ( next_ancestor) = ancestors. next ( ) {
0 commit comments