Skip to content

Commit

Permalink
minor: Use placeholders in unwrap_return_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga-Bowser committed Nov 17, 2024
1 parent f258164 commit 8542c04
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions crates/ide-assists/src/handlers/unwrap_return_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) ->
continue;
}

editor.replace(path_expr.syntax(), make.expr_unit().syntax());
let new_tail_expr = make.expr_unit();
editor.replace(path_expr.syntax(), new_tail_expr.syntax());
if let Some(cap) = ctx.config.snippet_cap {
editor.add_annotation(
new_tail_expr.syntax(),
builder.make_placeholder_snippet(cap),
);
}
}
_ => (),
}
Expand Down Expand Up @@ -302,7 +309,42 @@ fn foo() -> i32 {
if true {
42
} else {
()
${0:()}
}
}
"#,
"Unwrap Option return type",
);
}

#[test]
fn unwrap_option_return_type_multi_none() {
check_assist_by_label(
unwrap_return_type,
r#"
//- minicore: option
fn foo() -> Option<i3$02> {
if false {
return None;
}
if true {
Some(42)
} else {
None
}
}
"#,
r#"
fn foo() -> i32 {
if false {
return ${1:()};
}
if true {
42
} else {
${0:()}
}
}
"#,
Expand Down

0 comments on commit 8542c04

Please sign in to comment.