diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-12 17:16:02 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-12 17:16:02 +0000 |
commit | 4d51b5644458c7dcb97a4d445f1b379cd2548a78 (patch) | |
tree | e67df57ec40bd510028d0002306debd8c73f61b8 /crates/assists/src/handlers/generate_new.rs | |
parent | 29bc6b45fbcefc3369c14035126a8b0510b2ef60 (diff) | |
parent | ac959b82b3408fafd22f4fbb59e10383a18c545f (diff) |
Merge #7650
7650: Add `find_impl_block_end` assist helper r=Veykril a=yoshuawuyts
Fixes #7605. This makes it so assists can use helpers to either append a method to the start or the end of an `impl` block. Thanks!
@Veykril if this is merged, perhaps it could be good to update the gif in https://github.com/rust-analyzer/rust-analyzer/pull/7617#issuecomment-776622135 ? -- this should fix the ordering issue when generating multiple methods.
Co-authored-by: Yoshua Wuyts <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers/generate_new.rs')
-rw-r--r-- | crates/assists/src/handlers/generate_new.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/assists/src/handlers/generate_new.rs b/crates/assists/src/handlers/generate_new.rs index c29077225..8ce5930b7 100644 --- a/crates/assists/src/handlers/generate_new.rs +++ b/crates/assists/src/handlers/generate_new.rs | |||
@@ -4,7 +4,7 @@ use stdx::format_to; | |||
4 | use syntax::ast::{self, AstNode, NameOwner, StructKind, VisibilityOwner}; | 4 | use syntax::ast::{self, AstNode, NameOwner, StructKind, VisibilityOwner}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | utils::{find_impl_block, find_struct_impl, generate_impl_text}, | 7 | utils::{find_impl_block_start, find_struct_impl, generate_impl_text}, |
8 | AssistContext, AssistId, AssistKind, Assists, | 8 | AssistContext, AssistId, AssistKind, Assists, |
9 | }; | 9 | }; |
10 | 10 | ||
@@ -58,7 +58,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
58 | format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); | 58 | format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); |
59 | 59 | ||
60 | let start_offset = impl_def | 60 | let start_offset = impl_def |
61 | .and_then(|impl_def| find_impl_block(impl_def, &mut buf)) | 61 | .and_then(|impl_def| find_impl_block_start(impl_def, &mut buf)) |
62 | .unwrap_or_else(|| { | 62 | .unwrap_or_else(|| { |
63 | buf = generate_impl_text(&Adt::Struct(strukt.clone()), &buf); | 63 | buf = generate_impl_text(&Adt::Struct(strukt.clone()), &buf); |
64 | strukt.syntax().text_range().end() | 64 | strukt.syntax().text_range().end() |