diff options
Diffstat (limited to 'crates/assists/src/handlers/generate_setter.rs')
-rw-r--r-- | crates/assists/src/handlers/generate_setter.rs | 40 |
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; | |||
3 | use syntax::ast::{self, AstNode, NameOwner}; | 3 | use syntax::ast::{self, AstNode, NameOwner}; |
4 | 4 | ||
5 | use crate::{ | 5 | use 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#" | ||
168 | struct Context<T: Clone> { | ||
169 | data: T, | ||
170 | cou$0nt: usize, | ||
171 | } | ||
172 | |||
173 | impl<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#" | ||
180 | struct Context<T: Clone> { | ||
181 | data: T, | ||
182 | count: usize, | ||
183 | } | ||
184 | |||
185 | impl<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 | } |