From ac959b82b3408fafd22f4fbb59e10383a18c545f Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 12 Feb 2021 11:48:43 +0100 Subject: Add `find_impl_block_end` assist helper --- crates/assists/src/handlers/generate_setter.rs | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'crates/assists/src/handlers/generate_setter.rs') diff --git a/crates/assists/src/handlers/generate_setter.rs b/crates/assists/src/handlers/generate_setter.rs index c9043a162..b655f9b9c 100644 --- a/crates/assists/src/handlers/generate_setter.rs +++ b/crates/assists/src/handlers/generate_setter.rs @@ -3,7 +3,7 @@ use syntax::ast::VisibilityOwner; use syntax::ast::{self, AstNode, NameOwner}; use crate::{ - utils::{find_impl_block, find_struct_impl, generate_impl_text}, + utils::{find_impl_block_end, find_struct_impl, generate_impl_text}, AssistContext, AssistId, AssistKind, Assists, }; @@ -79,7 +79,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext) -> Option< ); let start_offset = impl_def - .and_then(|impl_def| find_impl_block(impl_def, &mut buf)) + .and_then(|impl_def| find_impl_block_end(impl_def, &mut buf)) .unwrap_or_else(|| { buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf); strukt.syntax().text_range().end() @@ -156,6 +156,42 @@ impl Person { pub(crate) fn set_data(&mut self, data: T) { self.data = data; } +}"#, + ); + } + + #[test] + fn test_multiple_generate_setter() { + check_assist( + generate_setter, + r#" +struct Context { + data: T, + cou$0nt: usize, +} + +impl Context { + /// Set the context's data. + fn set_data(&mut self, data: T) { + self.data = data; + } +}"#, + r#" +struct Context { + data: T, + count: usize, +} + +impl Context { + /// Set the context's data. + fn set_data(&mut self, data: T) { + self.data = data; + } + + /// Set the context's count. + fn set_count(&mut self, count: usize) { + self.count = count; + } }"#, ); } -- cgit v1.2.3