Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions crates/ide-assists/src/handlers/add_braces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use either::Either;
use syntax::{
AstNode,
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
ast::{self, edit::AstNodeEdit, syntax_factory::SyntaxFactory},
};

use crate::{AssistContext, AssistId, Assists};
Expand Down Expand Up @@ -43,10 +43,10 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
let make = SyntaxFactory::with_mappings();
let mut editor = builder.make_editor(expr.syntax());

let block_expr = make.block_expr(None, Some(expr.clone()));
block_expr.indent(expr.indent_level());
let new_expr = expr.reset_indent().indent(1.into());
let block_expr = make.block_expr(None, Some(new_expr));

editor.replace(expr.syntax(), block_expr.syntax());
editor.replace(expr.syntax(), block_expr.indent(expr.indent_level()).syntax());

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
Expand Down Expand Up @@ -171,6 +171,41 @@ fn foo() {
);
}

#[test]
fn multiple_indent() {
check_assist(
add_braces,
r#"
fn foo() {
{
match n {
Some(n) $0=> foo(
29,
30,
),
_ => ()
};
}
}
"#,
r#"
fn foo() {
{
match n {
Some(n) => {
foo(
29,
30,
)
},
_ => ()
};
}
}
"#,
);
}

#[test]
fn no_assist_for_match_with_braces() {
check_assist_not_applicable(
Expand Down