Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 10 additions & 11 deletions crates/ide-assists/src/handlers/expand_rest_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, Assists};
// struct Bar { y: Y, z: Z }
//
// fn foo(bar: Bar) {
// let Bar { y, z } = bar;
// let Bar { y, z } = bar;
// }
// ```
fn expand_record_rest_pattern(
Expand Down Expand Up @@ -53,18 +53,17 @@ fn expand_record_rest_pattern(
|builder| {
let make = SyntaxFactory::with_mappings();
let mut editor = builder.make_editor(rest_pat.syntax());
let new_field_list = make.record_pat_field_list(old_field_list.fields(), None);
for (f, _) in missing_fields.iter() {
let field = make.record_pat_field_shorthand(
let new_fields = old_field_list.fields().chain(missing_fields.iter().map(|(f, _)| {
make.record_pat_field_shorthand(
make.ident_pat(
false,
false,
make.name(&f.name(ctx.sema.db).display_no_db(edition).to_smolstr()),
)
.into(),
);
new_field_list.add_field(field);
}
)
}));
let new_field_list = make.record_pat_field_list(new_fields, None);

editor.replace(old_field_list.syntax(), new_field_list.syntax());

Expand Down Expand Up @@ -211,7 +210,7 @@ enum Foo {
fn bar(foo: Foo) {
match foo {
Foo::A(_) => false,
Foo::B{ y, z } => true,
Foo::B{ y, z } => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this PR somehow fixes extra spacings here 👍

};
}
"#,
Expand Down Expand Up @@ -272,7 +271,7 @@ struct Bar {
}

fn foo(bar: Bar) {
let Bar { y, z } = bar;
let Bar { y, z } = bar;
}
"#,
);
Expand Down Expand Up @@ -376,7 +375,7 @@ macro_rules! position {
position!(usize);

fn macro_call(pos: Pos) {
let Pos { x, y } = pos;
let Pos { x, y } = pos;
}
"#,
);
Expand Down Expand Up @@ -420,7 +419,7 @@ enum_gen!(usize);
fn macro_call(foo: Foo) {
match foo {
Foo::A(_) => false,
Foo::B{ x, y } => true,
Foo::B{ x, y } => true,
}
}
"#,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/tests/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ fn foo(bar: Bar) {
struct Bar { y: Y, z: Z }

fn foo(bar: Bar) {
let Bar { y, z } = bar;
let Bar { y, z } = bar;
}
"#####,
)
Expand Down
Loading