aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers/generate_setter.rs
diff options
context:
space:
mode:
authorYoshua Wuyts <[email protected]>2021-02-12 10:48:43 +0000
committerYoshua Wuyts <[email protected]>2021-02-12 16:59:08 +0000
commitac959b82b3408fafd22f4fbb59e10383a18c545f (patch)
tree8be4edce5110c27e7f3fe2a40342f929eaac0402 /crates/assists/src/handlers/generate_setter.rs
parentcf44953210cbfe189043417690fabd0037a6e74e (diff)
Add `find_impl_block_end` assist helper
Diffstat (limited to 'crates/assists/src/handlers/generate_setter.rs')
-rw-r--r--crates/assists/src/handlers/generate_setter.rs40
1 files changed, 38 insertions, 2 deletions
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;
3use syntax::ast::{self, AstNode, NameOwner}; 3use syntax::ast::{self, AstNode, NameOwner};
4 4
5use crate::{ 5use crate::{
6 utils::{find_impl_block, find_struct_impl, generate_impl_text}, 6 utils::{find_impl_block_end, find_struct_impl, generate_impl_text},
7 AssistContext, AssistId, AssistKind, Assists, 7 AssistContext, AssistId, AssistKind, Assists,
8}; 8};
9 9
@@ -79,7 +79,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext) -> Option<
79 ); 79 );
80 80
81 let start_offset = impl_def 81 let start_offset = impl_def
82 .and_then(|impl_def| find_impl_block(impl_def, &mut buf)) 82 .and_then(|impl_def| find_impl_block_end(impl_def, &mut buf))
83 .unwrap_or_else(|| { 83 .unwrap_or_else(|| {
84 buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf); 84 buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf);
85 strukt.syntax().text_range().end() 85 strukt.syntax().text_range().end()
@@ -159,4 +159,40 @@ impl<T: Clone> Person<T> {
159}"#, 159}"#,
160 ); 160 );
161 } 161 }
162
163 #[test]
164 fn test_multiple_generate_setter() {
165 check_assist(
166 generate_setter,
167 r#"
168struct Context<T: Clone> {
169 data: T,
170 cou$0nt: usize,
171}
172
173impl<T: Clone> Context<T> {
174 /// Set the context's data.
175 fn set_data(&mut self, data: T) {
176 self.data = data;
177 }
178}"#,
179 r#"
180struct Context<T: Clone> {
181 data: T,
182 count: usize,
183}
184
185impl<T: Clone> Context<T> {
186 /// Set the context's data.
187 fn set_data(&mut self, data: T) {
188 self.data = data;
189 }
190
191 /// Set the context's count.
192 fn set_count(&mut self, count: usize) {
193 self.count = count;
194 }
195}"#,
196 );
197 }
162} 198}