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