diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-20 01:11:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-20 01:11:25 +0100 |
commit | efac093093f1bd598957822e9e859b33c5f13e1f (patch) | |
tree | fd502d36d055c26ad2ae73580ff0859bbf3ab302 /crates/ra_assists/src/handlers/add_missing_impl_members.rs | |
parent | b26dbf80090ccdd753b35d6254246229e9ff8728 (diff) | |
parent | 767d169a2ae543f28544e85e15bac1b6aa1cab23 (diff) |
Merge #4525
4525: Better cursor placement when adding impl members r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/add_missing_impl_members.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index d7aa06947..abacd4065 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -45,8 +45,8 @@ enum AddMissingImplMembersMode { | |||
45 | // } | 45 | // } |
46 | // | 46 | // |
47 | // impl Trait<u32> for () { | 47 | // impl Trait<u32> for () { |
48 | // $0fn foo(&self) -> u32 { | 48 | // fn foo(&self) -> u32 { |
49 | // todo!() | 49 | // ${0:todo!()} |
50 | // } | 50 | // } |
51 | // | 51 | // |
52 | // } | 52 | // } |
@@ -167,15 +167,23 @@ fn add_missing_impl_members_inner( | |||
167 | let original_range = impl_item_list.syntax().text_range(); | 167 | let original_range = impl_item_list.syntax().text_range(); |
168 | match ctx.config.snippet_cap { | 168 | match ctx.config.snippet_cap { |
169 | None => builder.replace(original_range, new_impl_item_list.to_string()), | 169 | None => builder.replace(original_range, new_impl_item_list.to_string()), |
170 | Some(cap) => builder.replace_snippet( | 170 | Some(cap) => { |
171 | cap, | 171 | let mut cursor = Cursor::Before(first_new_item.syntax()); |
172 | original_range, | 172 | let placeholder; |
173 | render_snippet( | 173 | if let ast::AssocItem::FnDef(func) = &first_new_item { |
174 | if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) { | ||
175 | if m.syntax().text() == "todo!()" { | ||
176 | placeholder = m; | ||
177 | cursor = Cursor::Replace(placeholder.syntax()); | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | builder.replace_snippet( | ||
174 | cap, | 182 | cap, |
175 | new_impl_item_list.syntax(), | 183 | original_range, |
176 | Cursor::Before(first_new_item.syntax()), | 184 | render_snippet(cap, new_impl_item_list.syntax(), cursor), |
177 | ), | 185 | ) |
178 | ), | 186 | } |
179 | }; | 187 | }; |
180 | }) | 188 | }) |
181 | } | 189 | } |
@@ -271,8 +279,8 @@ struct S; | |||
271 | 279 | ||
272 | impl Foo for S { | 280 | impl Foo for S { |
273 | fn bar(&self) {} | 281 | fn bar(&self) {} |
274 | $0fn foo(&self) { | 282 | fn foo(&self) { |
275 | todo!() | 283 | ${0:todo!()} |
276 | } | 284 | } |
277 | 285 | ||
278 | }"#, | 286 | }"#, |
@@ -291,8 +299,8 @@ impl Foo for S { <|> }"#, | |||
291 | trait Foo { fn foo(&self); } | 299 | trait Foo { fn foo(&self); } |
292 | struct S; | 300 | struct S; |
293 | impl Foo for S { | 301 | impl Foo for S { |
294 | $0fn foo(&self) { | 302 | fn foo(&self) { |
295 | todo!() | 303 | ${0:todo!()} |
296 | } | 304 | } |
297 | }"#, | 305 | }"#, |
298 | ); | 306 | ); |
@@ -310,8 +318,8 @@ impl Foo<u32> for S { <|> }"#, | |||
310 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 318 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
311 | struct S; | 319 | struct S; |
312 | impl Foo<u32> for S { | 320 | impl Foo<u32> for S { |
313 | $0fn foo(&self, t: u32) -> &u32 { | 321 | fn foo(&self, t: u32) -> &u32 { |
314 | todo!() | 322 | ${0:todo!()} |
315 | } | 323 | } |
316 | }"#, | 324 | }"#, |
317 | ); | 325 | ); |
@@ -329,8 +337,8 @@ impl<U> Foo<U> for S { <|> }"#, | |||
329 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 337 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
330 | struct S; | 338 | struct S; |
331 | impl<U> Foo<U> for S { | 339 | impl<U> Foo<U> for S { |
332 | $0fn foo(&self, t: U) -> &U { | 340 | fn foo(&self, t: U) -> &U { |
333 | todo!() | 341 | ${0:todo!()} |
334 | } | 342 | } |
335 | }"#, | 343 | }"#, |
336 | ); | 344 | ); |
@@ -348,8 +356,8 @@ impl Foo for S {}<|>"#, | |||
348 | trait Foo { fn foo(&self); } | 356 | trait Foo { fn foo(&self); } |
349 | struct S; | 357 | struct S; |
350 | impl Foo for S { | 358 | impl Foo for S { |
351 | $0fn foo(&self) { | 359 | fn foo(&self) { |
352 | todo!() | 360 | ${0:todo!()} |
353 | } | 361 | } |
354 | }"#, | 362 | }"#, |
355 | ) | 363 | ) |
@@ -373,8 +381,8 @@ mod foo { | |||
373 | } | 381 | } |
374 | struct S; | 382 | struct S; |
375 | impl foo::Foo for S { | 383 | impl foo::Foo for S { |
376 | $0fn foo(&self, bar: foo::Bar) { | 384 | fn foo(&self, bar: foo::Bar) { |
377 | todo!() | 385 | ${0:todo!()} |
378 | } | 386 | } |
379 | }"#, | 387 | }"#, |
380 | ); | 388 | ); |
@@ -398,8 +406,8 @@ mod foo { | |||
398 | } | 406 | } |
399 | struct S; | 407 | struct S; |
400 | impl foo::Foo for S { | 408 | impl foo::Foo for S { |
401 | $0fn foo(&self, bar: foo::Bar<u32>) { | 409 | fn foo(&self, bar: foo::Bar<u32>) { |
402 | todo!() | 410 | ${0:todo!()} |
403 | } | 411 | } |
404 | }"#, | 412 | }"#, |
405 | ); | 413 | ); |
@@ -423,8 +431,8 @@ mod foo { | |||
423 | } | 431 | } |
424 | struct S; | 432 | struct S; |
425 | impl foo::Foo<u32> for S { | 433 | impl foo::Foo<u32> for S { |
426 | $0fn foo(&self, bar: foo::Bar<u32>) { | 434 | fn foo(&self, bar: foo::Bar<u32>) { |
427 | todo!() | 435 | ${0:todo!()} |
428 | } | 436 | } |
429 | }"#, | 437 | }"#, |
430 | ); | 438 | ); |
@@ -451,8 +459,8 @@ mod foo { | |||
451 | struct Param; | 459 | struct Param; |
452 | struct S; | 460 | struct S; |
453 | impl foo::Foo<Param> for S { | 461 | impl foo::Foo<Param> for S { |
454 | $0fn foo(&self, bar: Param) { | 462 | fn foo(&self, bar: Param) { |
455 | todo!() | 463 | ${0:todo!()} |
456 | } | 464 | } |
457 | }"#, | 465 | }"#, |
458 | ); | 466 | ); |
@@ -478,8 +486,8 @@ mod foo { | |||
478 | } | 486 | } |
479 | struct S; | 487 | struct S; |
480 | impl foo::Foo for S { | 488 | impl foo::Foo for S { |
481 | $0fn foo(&self, bar: foo::Bar<u32>::Assoc) { | 489 | fn foo(&self, bar: foo::Bar<u32>::Assoc) { |
482 | todo!() | 490 | ${0:todo!()} |
483 | } | 491 | } |
484 | }"#, | 492 | }"#, |
485 | ); | 493 | ); |
@@ -505,8 +513,8 @@ mod foo { | |||
505 | } | 513 | } |
506 | struct S; | 514 | struct S; |
507 | impl foo::Foo for S { | 515 | impl foo::Foo for S { |
508 | $0fn foo(&self, bar: foo::Bar<foo::Baz>) { | 516 | fn foo(&self, bar: foo::Bar<foo::Baz>) { |
509 | todo!() | 517 | ${0:todo!()} |
510 | } | 518 | } |
511 | }"#, | 519 | }"#, |
512 | ); | 520 | ); |
@@ -530,8 +538,8 @@ mod foo { | |||
530 | } | 538 | } |
531 | struct S; | 539 | struct S; |
532 | impl foo::Foo for S { | 540 | impl foo::Foo for S { |
533 | $0fn foo(&self, bar: dyn Fn(u32) -> i32) { | 541 | fn foo(&self, bar: dyn Fn(u32) -> i32) { |
534 | todo!() | 542 | ${0:todo!()} |
535 | } | 543 | } |
536 | }"#, | 544 | }"#, |
537 | ); | 545 | ); |
@@ -645,8 +653,8 @@ trait Foo<T = Self> { | |||
645 | 653 | ||
646 | struct S; | 654 | struct S; |
647 | impl Foo for S { | 655 | impl Foo for S { |
648 | $0fn bar(&self, other: &Self) { | 656 | fn bar(&self, other: &Self) { |
649 | todo!() | 657 | ${0:todo!()} |
650 | } | 658 | } |
651 | }"#, | 659 | }"#, |
652 | ) | 660 | ) |
@@ -670,8 +678,8 @@ trait Foo<T1, T2 = Self> { | |||
670 | 678 | ||
671 | struct S<T>; | 679 | struct S<T>; |
672 | impl Foo<T> for S<T> { | 680 | impl Foo<T> for S<T> { |
673 | $0fn bar(&self, this: &T, that: &Self) { | 681 | fn bar(&self, this: &T, that: &Self) { |
674 | todo!() | 682 | ${0:todo!()} |
675 | } | 683 | } |
676 | }"#, | 684 | }"#, |
677 | ) | 685 | ) |