From 75a012361409349d0325c9232e0c8fe8d52de505 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 May 2021 12:41:48 +0300 Subject: fix: don't add extra whitespace around fields closes #8785 --- .../src/diagnostics/fixes/fill_missing_fields.rs | 25 ++++++++++++++++++++++ crates/syntax/src/ast/edit_in_place.rs | 4 ++++ 2 files changed, 29 insertions(+) (limited to 'crates') diff --git a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs index 123c2f0af..37a0e37a9 100644 --- a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs +++ b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs @@ -186,6 +186,31 @@ fn test_fn() { let one = 1; let s = TestStruct{ ..a }; } +"#, + ); + } + + #[test] + fn test_fill_struct_fields_blank_line() { + check_fix( + r#" +struct S { a: (), b: () } + +fn f() { + S { + $0 + }; +} +"#, + r#" +struct S { a: (), b: () } + +fn f() { + S { + a: (), + b: (), + }; +} "#, ); } diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index 14624c682..2676ed8c9 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -378,6 +378,10 @@ impl ast::RecordExprFieldList { make::tokens::single_space() }; + if is_multiline { + normalize_ws_between_braces(self.syntax()); + } + let position = match self.fields().last() { Some(last_field) => { let comma = match last_field -- cgit v1.2.3