@@ -92,6 +92,7 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
9292 editor. replace ( type_ref. syntax ( ) , happy_type. syntax ( ) ) ;
9393 }
9494
95+ let mut final_placeholder = None ;
9596 for tail_expr in exprs_to_unwrap {
9697 match & tail_expr {
9798 ast:: Expr :: CallExpr ( call_expr) => {
@@ -145,12 +146,27 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
145146 continue ;
146147 }
147148
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+ }
149159 }
150160 _ => ( ) ,
151161 }
152162 }
153163
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+
154170 editor. add_mappings ( make. finish_with_mappings ( ) ) ;
155171 builder. add_file_edits ( ctx. file_id ( ) , editor) ;
156172 } )
@@ -300,7 +316,42 @@ fn foo() -> i32 {
300316 if true {
301317 42
302318 } 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
304355 }
305356}
306357"# ,
0 commit comments