Skip to content

Commit 57875bd

Browse files
authored
Merge pull request #20850 from A4-Tacks/add-mis-match-arms-indent
Migrate `add_missing_match_arms` assist, because edit_in_place uses ted
2 parents 62eee18 + ed428f1 commit 57875bd

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use ide_db::syntax_helpers::suggest_name;
88
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast};
99
use itertools::Itertools;
1010
use syntax::ToSmolStr;
11-
use syntax::ast::edit::IndentLevel;
12-
use syntax::ast::edit_in_place::Indent;
11+
use syntax::ast::edit::{AstNodeEdit, IndentLevel};
1312
use syntax::ast::syntax_factory::SyntaxFactory;
1413
use syntax::ast::{self, AstNode, MatchArmList, MatchExpr, Pat, make};
1514

@@ -261,6 +260,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
261260
true
262261
}
263262
})
263+
.map(|arm| arm.reset_indent().indent(IndentLevel(1)))
264264
.collect();
265265

266266
let first_new_arm_idx = arms.len();
@@ -300,7 +300,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
300300
};
301301

302302
let mut editor = builder.make_editor(&old_place);
303-
new_match_arm_list.indent(IndentLevel::from_node(&old_place));
303+
let new_match_arm_list = new_match_arm_list.indent(IndentLevel::from_node(&old_place));
304304
editor.replace(old_place, new_match_arm_list.syntax());
305305

306306
if let Some(cap) = ctx.config.snippet_cap {
@@ -917,6 +917,39 @@ fn main() {
917917
);
918918
}
919919

920+
#[test]
921+
fn partial_fill_option_with_indentation() {
922+
check_assist(
923+
add_missing_match_arms,
924+
r#"
925+
//- minicore: option
926+
fn main() {
927+
match None$0 {
928+
None => {
929+
foo(
930+
"foo",
931+
"bar",
932+
);
933+
}
934+
}
935+
}
936+
"#,
937+
r#"
938+
fn main() {
939+
match None {
940+
None => {
941+
foo(
942+
"foo",
943+
"bar",
944+
);
945+
}
946+
Some(${1:_}) => ${2:todo!()},$0
947+
}
948+
}
949+
"#,
950+
);
951+
}
952+
920953
#[test]
921954
fn partial_fill_or_pat() {
922955
check_assist(

0 commit comments

Comments
 (0)