diff options
Diffstat (limited to 'crates/assists/src/handlers/generate_getter_mut.rs')
-rw-r--r-- | crates/assists/src/handlers/generate_getter_mut.rs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/crates/assists/src/handlers/generate_getter_mut.rs b/crates/assists/src/handlers/generate_getter_mut.rs index b5085035e..bf0d99881 100644 --- a/crates/assists/src/handlers/generate_getter_mut.rs +++ b/crates/assists/src/handlers/generate_getter_mut.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 | ||
@@ -76,7 +76,7 @@ pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext) -> Opt | |||
76 | ); | 76 | ); |
77 | 77 | ||
78 | let start_offset = impl_def | 78 | let start_offset = impl_def |
79 | .and_then(|impl_def| find_impl_block(impl_def, &mut buf)) | 79 | .and_then(|impl_def| find_impl_block_end(impl_def, &mut buf)) |
80 | .unwrap_or_else(|| { | 80 | .unwrap_or_else(|| { |
81 | buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf); | 81 | buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf); |
82 | strukt.syntax().text_range().end() | 82 | strukt.syntax().text_range().end() |
@@ -156,4 +156,40 @@ impl<T: Clone> Context<T> { | |||
156 | }"#, | 156 | }"#, |
157 | ); | 157 | ); |
158 | } | 158 | } |
159 | |||
160 | #[test] | ||
161 | fn test_multiple_generate_getter_mut() { | ||
162 | check_assist( | ||
163 | generate_getter_mut, | ||
164 | r#" | ||
165 | struct Context<T: Clone> { | ||
166 | data: T, | ||
167 | cou$0nt: usize, | ||
168 | } | ||
169 | |||
170 | impl<T: Clone> Context<T> { | ||
171 | /// Get a mutable reference to the context's data. | ||
172 | fn data_mut(&mut self) -> &mut T { | ||
173 | &mut self.data | ||
174 | } | ||
175 | }"#, | ||
176 | r#" | ||
177 | struct Context<T: Clone> { | ||
178 | data: T, | ||
179 | count: usize, | ||
180 | } | ||
181 | |||
182 | impl<T: Clone> Context<T> { | ||
183 | /// Get a mutable reference to the context's data. | ||
184 | fn data_mut(&mut self) -> &mut T { | ||
185 | &mut self.data | ||
186 | } | ||
187 | |||
188 | /// Get a mutable reference to the context's count. | ||
189 | fn count_mut(&mut self) -> &mut usize { | ||
190 | &mut self.count | ||
191 | } | ||
192 | }"#, | ||
193 | ); | ||
194 | } | ||
159 | } | 195 | } |