diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-17 12:11:31 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-17 12:11:31 +0100 |
commit | 112fd0ec7d65b5f23865410fd3e188e761d97110 (patch) | |
tree | 40f4cde1d0d97c38f9402a9e2edbc5dfb646e93f /crates | |
parent | 4c8e6e89aa05ea654534715399fe178f14a3b85a (diff) | |
parent | a27fc96aa1fc8a96ea3262c898fae393c2e4ba0b (diff) |
Merge #1160
1160: better formatting when adding trait members r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/add_missing_impl_members.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs index 100ebb7b6..c82447b84 100644 --- a/crates/ra_assists/src/add_missing_impl_members.rs +++ b/crates/ra_assists/src/add_missing_impl_members.rs | |||
@@ -109,6 +109,7 @@ fn add_missing_impl_members_inner( | |||
109 | let replaced_text_range = TextUnit::of_str(&func_bodies); | 109 | let replaced_text_range = TextUnit::of_str(&func_bodies); |
110 | 110 | ||
111 | edit.replace(changed_range, func_bodies); | 111 | edit.replace(changed_range, func_bodies); |
112 | // FIXME: place the cursor on the first unimplemented? | ||
112 | edit.set_cursor( | 113 | edit.set_cursor( |
113 | changed_range.start() + replaced_text_range - TextUnit::of_str(&trailing_whitespace), | 114 | changed_range.start() + replaced_text_range - TextUnit::of_str(&trailing_whitespace), |
114 | ); | 115 | ); |
@@ -138,7 +139,7 @@ fn build_func_body(def: &ast::FnDef) -> String { | |||
138 | 139 | ||
139 | for child in def.syntax().children_with_tokens() { | 140 | for child in def.syntax().children_with_tokens() { |
140 | match (child.prev_sibling_or_token().map(|c| c.kind()), child.kind()) { | 141 | match (child.prev_sibling_or_token().map(|c| c.kind()), child.kind()) { |
141 | (_, SyntaxKind::SEMI) => buf.push_str(" { unimplemented!() }"), | 142 | (_, SyntaxKind::SEMI) => buf.push_str(" {\n unimplemented!()\n}"), |
142 | (_, SyntaxKind::ATTR) | (_, SyntaxKind::COMMENT) => {} | 143 | (_, SyntaxKind::ATTR) | (_, SyntaxKind::COMMENT) => {} |
143 | (Some(SyntaxKind::ATTR), SyntaxKind::WHITESPACE) | 144 | (Some(SyntaxKind::ATTR), SyntaxKind::WHITESPACE) |
144 | | (Some(SyntaxKind::COMMENT), SyntaxKind::WHITESPACE) => {} | 145 | | (Some(SyntaxKind::COMMENT), SyntaxKind::WHITESPACE) => {} |
@@ -182,8 +183,12 @@ struct S; | |||
182 | 183 | ||
183 | impl Foo for S { | 184 | impl Foo for S { |
184 | fn bar(&self) {} | 185 | fn bar(&self) {} |
185 | fn foo(&self) { unimplemented!() } | 186 | fn foo(&self) { |
186 | fn baz(&self) { unimplemented!() }<|> | 187 | unimplemented!() |
188 | } | ||
189 | fn baz(&self) { | ||
190 | unimplemented!() | ||
191 | }<|> | ||
187 | }", | 192 | }", |
188 | ); | 193 | ); |
189 | } | 194 | } |
@@ -216,7 +221,9 @@ struct S; | |||
216 | 221 | ||
217 | impl Foo for S { | 222 | impl Foo for S { |
218 | fn bar(&self) {} | 223 | fn bar(&self) {} |
219 | fn foo(&self) { unimplemented!() }<|> | 224 | fn foo(&self) { |
225 | unimplemented!() | ||
226 | }<|> | ||
220 | }", | 227 | }", |
221 | ); | 228 | ); |
222 | } | 229 | } |
@@ -233,7 +240,9 @@ impl Foo for S { <|> }", | |||
233 | trait Foo { fn foo(&self); } | 240 | trait Foo { fn foo(&self); } |
234 | struct S; | 241 | struct S; |
235 | impl Foo for S { | 242 | impl Foo for S { |
236 | fn foo(&self) { unimplemented!() }<|> | 243 | fn foo(&self) { |
244 | unimplemented!() | ||
245 | }<|> | ||
237 | }", | 246 | }", |
238 | ); | 247 | ); |
239 | } | 248 | } |
@@ -250,7 +259,9 @@ impl Foo for S {}<|>", | |||
250 | trait Foo { fn foo(&self); } | 259 | trait Foo { fn foo(&self); } |
251 | struct S; | 260 | struct S; |
252 | impl Foo for S { | 261 | impl Foo for S { |
253 | fn foo(&self) { unimplemented!() }<|> | 262 | fn foo(&self) { |
263 | unimplemented!() | ||
264 | }<|> | ||
254 | }", | 265 | }", |
255 | ) | 266 | ) |
256 | } | 267 | } |
@@ -301,7 +312,9 @@ struct S; | |||
301 | 312 | ||
302 | mod my_mod { | 313 | mod my_mod { |
303 | impl crate::Foo for S { | 314 | impl crate::Foo for S { |
304 | fn valid(some: u32) -> bool { unimplemented!() }<|> | 315 | fn valid(some: u32) -> bool { |
316 | unimplemented!() | ||
317 | }<|> | ||
305 | } | 318 | } |
306 | }", | 319 | }", |
307 | ) | 320 | ) |
@@ -329,7 +342,9 @@ trait Foo { | |||
329 | } | 342 | } |
330 | struct S; | 343 | struct S; |
331 | impl Foo for S { | 344 | impl Foo for S { |
332 | fn foo(&self) { unimplemented!() }<|> | 345 | fn foo(&self) { |
346 | unimplemented!() | ||
347 | }<|> | ||
333 | }"#, | 348 | }"#, |
334 | ) | 349 | ) |
335 | } | 350 | } |