aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-21 22:52:21 +0100
committerAleksey Kladov <[email protected]>2019-04-21 22:52:21 +0100
commit97f41d7343a4801f296cd6a7a45ece9249c15886 (patch)
treef50302f9e71ebcd7042df620b0f1cc21b9714574 /crates/ra_assists
parentf313ac45af0b9c81cf411a8a4a6873e742bb8562 (diff)
test short structs
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/ast_editor.rs15
-rw-r--r--crates/ra_assists/src/fill_struct_fields.rs27
2 files changed, 38 insertions, 4 deletions
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs
index 5bf1fc0ed..7ef58aa8e 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -110,13 +110,20 @@ impl AstEditor<ast::NamedFieldList> {
110 110
111 let position = match position { 111 let position = match position {
112 InsertPosition::First => after_l_curly!(), 112 InsertPosition::First => after_l_curly!(),
113 InsertPosition::Last => match self.ast().fields().last() { 113 InsertPosition::Last => {
114 Some(it) => after_field!(it), 114 if !is_multiline {
115 None => after_l_curly!(), 115 // don't insert comma before curly
116 }, 116 to_insert.pop();
117 }
118 match self.ast().fields().last() {
119 Some(it) => after_field!(it),
120 None => after_l_curly!(),
121 }
122 }
117 InsertPosition::Before(anchor) => InsertPosition::Before(anchor.syntax().into()), 123 InsertPosition::Before(anchor) => InsertPosition::Before(anchor.syntax().into()),
118 InsertPosition::After(anchor) => after_field!(anchor), 124 InsertPosition::After(anchor) => after_field!(anchor),
119 }; 125 };
126
120 self.ast = self.insert_children(position, to_insert.iter().cloned()); 127 self.ast = self.insert_children(position, to_insert.iter().cloned());
121 } 128 }
122 129
diff --git a/crates/ra_assists/src/fill_struct_fields.rs b/crates/ra_assists/src/fill_struct_fields.rs
index ca128168a..302d62ab1 100644
--- a/crates/ra_assists/src/fill_struct_fields.rs
+++ b/crates/ra_assists/src/fill_struct_fields.rs
@@ -194,4 +194,31 @@ mod tests {
194 "#, 194 "#,
195 ); 195 );
196 } 196 }
197
198 #[test]
199 fn fill_struct_short() {
200 check_assist(
201 fill_struct_fields,
202 r#"
203 struct S {
204 foo: u32,
205 bar: String,
206 }
207
208 fn main() {
209 let s = S {<|> };
210 }
211 "#,
212 r#"
213 struct S {
214 foo: u32,
215 bar: String,
216 }
217
218 fn main() {
219 let s = <|>S { foo: (), bar: () };
220 }
221 "#,
222 );
223 }
197} 224}