diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 203 |
1 files changed, 146 insertions, 57 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 5cf55a496..6878008d3 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -182,80 +182,169 @@ impl Completions { | |||
182 | 182 | ||
183 | #[cfg(test)] | 183 | #[cfg(test)] |
184 | mod tests { | 184 | mod tests { |
185 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | ||
186 | use insta::assert_debug_snapshot_matches; | ||
185 | use test_utils::covers; | 187 | use test_utils::covers; |
186 | 188 | ||
187 | use crate::completion::{check_completion, CompletionKind}; | 189 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { |
188 | 190 | do_completion(code, CompletionKind::Reference) | |
189 | fn check_reference_completion(code: &str, expected_completions: &str) { | ||
190 | check_completion(code, expected_completions, CompletionKind::Reference); | ||
191 | } | 191 | } |
192 | 192 | ||
193 | #[test] | 193 | #[test] |
194 | fn inserts_parens_for_function_calls() { | 194 | fn inserts_parens_for_function_calls() { |
195 | covers!(inserts_parens_for_function_calls); | 195 | covers!(inserts_parens_for_function_calls); |
196 | check_reference_completion( | 196 | assert_debug_snapshot_matches!( |
197 | "inserts_parens_for_function_calls1", | 197 | do_reference_completion( |
198 | r" | 198 | r" |
199 | fn no_args() {} | 199 | fn no_args() {} |
200 | fn main() { no_<|> } | 200 | fn main() { no_<|> } |
201 | ", | 201 | " |
202 | ), | ||
203 | @r###"[ | ||
204 | CompletionItem { | ||
205 | label: "main", | ||
206 | source_range: [61; 64), | ||
207 | delete: [61; 64), | ||
208 | insert: "main()$0", | ||
209 | kind: Function, | ||
210 | detail: "fn main()", | ||
211 | }, | ||
212 | CompletionItem { | ||
213 | label: "no_args", | ||
214 | source_range: [61; 64), | ||
215 | delete: [61; 64), | ||
216 | insert: "no_args()$0", | ||
217 | kind: Function, | ||
218 | detail: "fn no_args()", | ||
219 | }, | ||
220 | ]"### | ||
202 | ); | 221 | ); |
203 | check_reference_completion( | 222 | assert_debug_snapshot_matches!( |
204 | "inserts_parens_for_function_calls2", | 223 | do_reference_completion( |
205 | r" | 224 | r" |
206 | fn with_args(x: i32, y: String) {} | 225 | fn with_args(x: i32, y: String) {} |
207 | fn main() { with_<|> } | 226 | fn main() { with_<|> } |
208 | ", | 227 | " |
228 | ), | ||
229 | @r###"[ | ||
230 | CompletionItem { | ||
231 | label: "main", | ||
232 | source_range: [80; 85), | ||
233 | delete: [80; 85), | ||
234 | insert: "main()$0", | ||
235 | kind: Function, | ||
236 | detail: "fn main()", | ||
237 | }, | ||
238 | CompletionItem { | ||
239 | label: "with_args", | ||
240 | source_range: [80; 85), | ||
241 | delete: [80; 85), | ||
242 | insert: "with_args($0)", | ||
243 | kind: Function, | ||
244 | detail: "fn with_args(x: i32, y: String)", | ||
245 | }, | ||
246 | ]"### | ||
247 | ); | ||
248 | assert_debug_snapshot_matches!( | ||
249 | do_reference_completion( | ||
250 | r" | ||
251 | struct S {} | ||
252 | impl S { | ||
253 | fn foo(&self) {} | ||
254 | } | ||
255 | fn bar(s: &S) { | ||
256 | s.f<|> | ||
257 | } | ||
258 | " | ||
259 | ), | ||
260 | @r###"[ | ||
261 | CompletionItem { | ||
262 | label: "foo", | ||
263 | source_range: [163; 164), | ||
264 | delete: [163; 164), | ||
265 | insert: "foo()$0", | ||
266 | kind: Method, | ||
267 | detail: "fn foo(&self)", | ||
268 | }, | ||
269 | ]"### | ||
209 | ); | 270 | ); |
210 | check_reference_completion( | ||
211 | "inserts_parens_for_function_calls3", | ||
212 | r" | ||
213 | struct S {} | ||
214 | impl S { | ||
215 | fn foo(&self) {} | ||
216 | } | ||
217 | fn bar(s: &S) { | ||
218 | s.f<|> | ||
219 | } | ||
220 | ", | ||
221 | ) | ||
222 | } | 271 | } |
223 | 272 | ||
224 | #[test] | 273 | #[test] |
225 | fn dont_render_function_parens_in_use_item() { | 274 | fn dont_render_function_parens_in_use_item() { |
226 | check_reference_completion( | 275 | assert_debug_snapshot_matches!( |
227 | "dont_render_function_parens_in_use_item", | 276 | do_reference_completion( |
228 | " | 277 | " |
229 | //- /lib.rs | 278 | //- /lib.rs |
230 | mod m { pub fn foo() {} } | 279 | mod m { pub fn foo() {} } |
231 | use crate::m::f<|>; | 280 | use crate::m::f<|>; |
232 | ", | 281 | " |
233 | ) | 282 | ), |
283 | @r#"[ | ||
284 | CompletionItem { | ||
285 | label: "foo", | ||
286 | source_range: [40; 41), | ||
287 | delete: [40; 41), | ||
288 | insert: "foo", | ||
289 | kind: Function, | ||
290 | detail: "pub fn foo()", | ||
291 | }, | ||
292 | ]"# | ||
293 | ); | ||
234 | } | 294 | } |
235 | 295 | ||
236 | #[test] | 296 | #[test] |
237 | fn dont_render_function_parens_if_already_call() { | 297 | fn dont_render_function_parens_if_already_call() { |
238 | check_reference_completion( | 298 | assert_debug_snapshot_matches!( |
239 | "dont_render_function_parens_if_already_call", | 299 | do_reference_completion( |
240 | " | 300 | " |
241 | //- /lib.rs | 301 | //- /lib.rs |
242 | fn frobnicate() {} | 302 | fn frobnicate() {} |
243 | fn main() { | 303 | fn main() { |
244 | frob<|>(); | 304 | frob<|>(); |
245 | } | 305 | } |
246 | ", | 306 | " |
307 | ), | ||
308 | @r#"[ | ||
309 | CompletionItem { | ||
310 | label: "frobnicate", | ||
311 | source_range: [35; 39), | ||
312 | delete: [35; 39), | ||
313 | insert: "frobnicate", | ||
314 | kind: Function, | ||
315 | detail: "fn frobnicate()", | ||
316 | }, | ||
317 | CompletionItem { | ||
318 | label: "main", | ||
319 | source_range: [35; 39), | ||
320 | delete: [35; 39), | ||
321 | insert: "main", | ||
322 | kind: Function, | ||
323 | detail: "fn main()", | ||
324 | }, | ||
325 | ]"# | ||
326 | ); | ||
327 | assert_debug_snapshot_matches!( | ||
328 | do_reference_completion( | ||
329 | " | ||
330 | //- /lib.rs | ||
331 | struct Foo {} | ||
332 | impl Foo { fn new() -> Foo {} } | ||
333 | fn main() { | ||
334 | Foo::ne<|>(); | ||
335 | } | ||
336 | " | ||
337 | ), | ||
338 | @r#"[ | ||
339 | CompletionItem { | ||
340 | label: "new", | ||
341 | source_range: [67; 69), | ||
342 | delete: [67; 69), | ||
343 | insert: "new", | ||
344 | kind: Function, | ||
345 | detail: "fn new() -> Foo", | ||
346 | }, | ||
347 | ]"# | ||
247 | ); | 348 | ); |
248 | check_reference_completion( | ||
249 | "dont_render_function_parens_if_already_call_assoc_fn", | ||
250 | " | ||
251 | //- /lib.rs | ||
252 | struct Foo {} | ||
253 | impl Foo { fn new() -> Foo {} } | ||
254 | fn main() { | ||
255 | Foo::ne<|>(); | ||
256 | } | ||
257 | ", | ||
258 | ) | ||
259 | } | 349 | } |
260 | |||
261 | } | 350 | } |