@@ -92,6 +92,7 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
92
92
editor. replace ( type_ref. syntax ( ) , happy_type. syntax ( ) ) ;
93
93
}
94
94
95
+ let mut final_placeholder = None ;
95
96
for tail_expr in exprs_to_unwrap {
96
97
match & tail_expr {
97
98
ast:: Expr :: CallExpr ( call_expr) => {
@@ -145,12 +146,27 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
145
146
continue ;
146
147
}
147
148
148
- editor. replace ( path_expr. syntax ( ) , make. expr_unit ( ) . syntax ( ) ) ;
149
+ let new_tail_expr = make. expr_unit ( ) ;
150
+ editor. replace ( path_expr. syntax ( ) , new_tail_expr. syntax ( ) ) ;
151
+ if let Some ( cap) = ctx. config . snippet_cap {
152
+ editor. add_annotation (
153
+ new_tail_expr. syntax ( ) ,
154
+ builder. make_placeholder_snippet ( cap) ,
155
+ ) ;
156
+
157
+ final_placeholder = Some ( new_tail_expr) ;
158
+ }
149
159
}
150
160
_ => ( ) ,
151
161
}
152
162
}
153
163
164
+ if let Some ( cap) = ctx. config . snippet_cap {
165
+ if let Some ( final_placeholder) = final_placeholder {
166
+ editor. add_annotation ( final_placeholder. syntax ( ) , builder. make_tabstop_after ( cap) ) ;
167
+ }
168
+ }
169
+
154
170
editor. add_mappings ( make. finish_with_mappings ( ) ) ;
155
171
builder. add_file_edits ( ctx. file_id ( ) , editor) ;
156
172
} )
@@ -300,7 +316,42 @@ fn foo() -> i32 {
300
316
if true {
301
317
42
302
318
} else {
303
- ()
319
+ ${1:()}$0
320
+ }
321
+ }
322
+ "# ,
323
+ "Unwrap Option return type" ,
324
+ ) ;
325
+ }
326
+
327
+ #[ test]
328
+ fn unwrap_option_return_type_multi_none ( ) {
329
+ check_assist_by_label (
330
+ unwrap_return_type,
331
+ r#"
332
+ //- minicore: option
333
+ fn foo() -> Option<i3$02> {
334
+ if false {
335
+ return None;
336
+ }
337
+
338
+ if true {
339
+ Some(42)
340
+ } else {
341
+ None
342
+ }
343
+ }
344
+ "# ,
345
+ r#"
346
+ fn foo() -> i32 {
347
+ if false {
348
+ return ${1:()};
349
+ }
350
+
351
+ if true {
352
+ 42
353
+ } else {
354
+ ${2:()}$0
304
355
}
305
356
}
306
357
"# ,
0 commit comments