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