diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide_assists/src/handlers/generate_getter.rs | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/crates/ide_assists/src/handlers/generate_getter.rs b/crates/ide_assists/src/handlers/generate_getter.rs index fbd47d761..c77395824 100644 --- a/crates/ide_assists/src/handlers/generate_getter.rs +++ b/crates/ide_assists/src/handlers/generate_getter.rs | |||
@@ -135,39 +135,43 @@ mod tests { | |||
135 | check_assist( | 135 | check_assist( |
136 | generate_getter, | 136 | generate_getter, |
137 | r#" | 137 | r#" |
138 | struct Context<T: Clone> { | 138 | struct Context { |
139 | dat$0a: T, | 139 | dat$0a: Data, |
140 | }"#, | 140 | } |
141 | "#, | ||
141 | r#" | 142 | r#" |
142 | struct Context<T: Clone> { | 143 | struct Context { |
143 | data: T, | 144 | data: Data, |
144 | } | 145 | } |
145 | 146 | ||
146 | impl<T: Clone> Context<T> { | 147 | impl Context { |
147 | /// Get a reference to the context's data. | 148 | /// Get a reference to the context's data. |
148 | fn data(&self) -> &T { | 149 | fn data(&self) -> &Data { |
149 | &self.data | 150 | &self.data |
150 | } | 151 | } |
151 | }"#, | 152 | } |
153 | "#, | ||
152 | ); | 154 | ); |
153 | 155 | ||
154 | check_assist( | 156 | check_assist( |
155 | generate_getter_mut, | 157 | generate_getter_mut, |
156 | r#" | 158 | r#" |
157 | struct Context<T: Clone> { | 159 | struct Context { |
158 | dat$0a: T, | 160 | dat$0a: Data, |
159 | }"#, | 161 | } |
162 | "#, | ||
160 | r#" | 163 | r#" |
161 | struct Context<T: Clone> { | 164 | struct Context { |
162 | data: T, | 165 | data: Data, |
163 | } | 166 | } |
164 | 167 | ||
165 | impl<T: Clone> Context<T> { | 168 | impl Context { |
166 | /// Get a mutable reference to the context's data. | 169 | /// Get a mutable reference to the context's data. |
167 | fn data_mut(&mut self) -> &mut T { | 170 | fn data_mut(&mut self) -> &mut Data { |
168 | &mut self.data | 171 | &mut self.data |
169 | } | 172 | } |
170 | }"#, | 173 | } |
174 | "#, | ||
171 | ); | 175 | ); |
172 | } | 176 | } |
173 | 177 | ||
@@ -176,29 +180,31 @@ impl<T: Clone> Context<T> { | |||
176 | check_assist_not_applicable( | 180 | check_assist_not_applicable( |
177 | generate_getter, | 181 | generate_getter, |
178 | r#" | 182 | r#" |
179 | struct Context<T: Clone> { | 183 | struct Context { |
180 | dat$0a: T, | 184 | dat$0a: Data, |
181 | } | 185 | } |
182 | 186 | ||
183 | impl<T: Clone> Context<T> { | 187 | impl Context { |
184 | fn data(&self) -> &T { | 188 | fn data(&self) -> &Data { |
185 | &self.data | 189 | &self.data |
186 | } | 190 | } |
187 | }"#, | 191 | } |
192 | "#, | ||
188 | ); | 193 | ); |
189 | 194 | ||
190 | check_assist_not_applicable( | 195 | check_assist_not_applicable( |
191 | generate_getter_mut, | 196 | generate_getter_mut, |
192 | r#" | 197 | r#" |
193 | struct Context<T: Clone> { | 198 | struct Context { |
194 | dat$0a: T, | 199 | dat$0a: Data, |
195 | } | 200 | } |
196 | 201 | ||
197 | impl<T: Clone> Context<T> { | 202 | impl Context { |
198 | fn data_mut(&mut self) -> &mut T { | 203 | fn data_mut(&mut self) -> &mut Data { |
199 | &mut self.data | 204 | &mut self.data |
200 | } | 205 | } |
201 | }"#, | 206 | } |
207 | "#, | ||
202 | ); | 208 | ); |
203 | } | 209 | } |
204 | 210 | ||
@@ -207,20 +213,22 @@ impl<T: Clone> Context<T> { | |||
207 | check_assist( | 213 | check_assist( |
208 | generate_getter, | 214 | generate_getter, |
209 | r#" | 215 | r#" |
210 | pub(crate) struct Context<T: Clone> { | 216 | pub(crate) struct Context { |
211 | dat$0a: T, | 217 | dat$0a: Data, |
212 | }"#, | 218 | } |
219 | "#, | ||
213 | r#" | 220 | r#" |
214 | pub(crate) struct Context<T: Clone> { | 221 | pub(crate) struct Context { |
215 | data: T, | 222 | data: Data, |
216 | } | 223 | } |
217 | 224 | ||
218 | impl<T: Clone> Context<T> { | 225 | impl Context { |
219 | /// Get a reference to the context's data. | 226 | /// Get a reference to the context's data. |
220 | pub(crate) fn data(&self) -> &T { | 227 | pub(crate) fn data(&self) -> &Data { |
221 | &self.data | 228 | &self.data |
222 | } | 229 | } |
223 | }"#, | 230 | } |
231 | "#, | ||
224 | ); | 232 | ); |
225 | } | 233 | } |
226 | 234 | ||
@@ -229,26 +237,27 @@ impl<T: Clone> Context<T> { | |||
229 | check_assist( | 237 | check_assist( |
230 | generate_getter, | 238 | generate_getter, |
231 | r#" | 239 | r#" |
232 | struct Context<T: Clone> { | 240 | struct Context { |
233 | data: T, | 241 | data: Data, |
234 | cou$0nt: usize, | 242 | cou$0nt: usize, |
235 | } | 243 | } |
236 | 244 | ||
237 | impl<T: Clone> Context<T> { | 245 | impl Context { |
238 | /// Get a reference to the context's data. | 246 | /// Get a reference to the context's data. |
239 | fn data(&self) -> &T { | 247 | fn data(&self) -> &Data { |
240 | &self.data | 248 | &self.data |
241 | } | 249 | } |
242 | }"#, | 250 | } |
251 | "#, | ||
243 | r#" | 252 | r#" |
244 | struct Context<T: Clone> { | 253 | struct Context { |
245 | data: T, | 254 | data: Data, |
246 | count: usize, | 255 | count: usize, |
247 | } | 256 | } |
248 | 257 | ||
249 | impl<T: Clone> Context<T> { | 258 | impl Context { |
250 | /// Get a reference to the context's data. | 259 | /// Get a reference to the context's data. |
251 | fn data(&self) -> &T { | 260 | fn data(&self) -> &Data { |
252 | &self.data | 261 | &self.data |
253 | } | 262 | } |
254 | 263 | ||
@@ -256,7 +265,8 @@ impl<T: Clone> Context<T> { | |||
256 | fn count(&self) -> &usize { | 265 | fn count(&self) -> &usize { |
257 | &self.count | 266 | &self.count |
258 | } | 267 | } |
259 | }"#, | 268 | } |
269 | "#, | ||
260 | ); | 270 | ); |
261 | } | 271 | } |
262 | } | 272 | } |