Skip to content

Commit f2c9293

Browse files
committed
minor: Use placeholders in unwrap_return_type
1 parent 1599511 commit f2c9293

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

crates/ide-assists/src/handlers/unwrap_return_type.rs

+44-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
147147
continue;
148148
}
149149

150-
editor.replace(path_expr.syntax(), make.expr_unit().syntax());
150+
let new_tail_expr = make.expr_unit();
151+
editor.replace(path_expr.syntax(), new_tail_expr.syntax());
152+
if let Some(cap) = ctx.config.snippet_cap {
153+
editor.add_annotation(
154+
new_tail_expr.syntax(),
155+
builder.make_placeholder_snippet(cap),
156+
);
157+
}
151158
}
152159
_ => (),
153160
}
@@ -302,7 +309,42 @@ fn foo() -> i32 {
302309
if true {
303310
42
304311
} else {
305-
()
312+
${0:()}
313+
}
314+
}
315+
"#,
316+
"Unwrap Option return type",
317+
);
318+
}
319+
320+
#[test]
321+
fn unwrap_option_return_type_multi_none() {
322+
check_assist_by_label(
323+
unwrap_return_type,
324+
r#"
325+
//- minicore: option
326+
fn foo() -> Option<i3$02> {
327+
if false {
328+
return None;
329+
}
330+
331+
if true {
332+
Some(42)
333+
} else {
334+
None
335+
}
336+
}
337+
"#,
338+
r#"
339+
fn foo() -> i32 {
340+
if false {
341+
return ${1:()};
342+
}
343+
344+
if true {
345+
42
346+
} else {
347+
${0:()}
306348
}
307349
}
308350
"#,

0 commit comments

Comments
 (0)