diff options
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/completion_item.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 48 |
2 files changed, 56 insertions, 4 deletions
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 1d14e9636..ef6848607 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs | |||
@@ -321,8 +321,17 @@ impl Into<Vec<CompletionItem>> for Completions { | |||
321 | 321 | ||
322 | #[cfg(test)] | 322 | #[cfg(test)] |
323 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | 323 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { |
324 | do_completion_with_options(code, kind, &crate::completion::CompletionOptions::default()) | ||
325 | } | ||
326 | |||
327 | #[cfg(test)] | ||
328 | pub(crate) fn do_completion_with_options( | ||
329 | code: &str, | ||
330 | kind: CompletionKind, | ||
331 | options: &crate::completion::CompletionOptions, | ||
332 | ) -> Vec<CompletionItem> { | ||
324 | use crate::{ | 333 | use crate::{ |
325 | completion::{completions, CompletionOptions}, | 334 | completion::completions, |
326 | mock_analysis::{analysis_and_position, single_file_with_position}, | 335 | mock_analysis::{analysis_and_position, single_file_with_position}, |
327 | }; | 336 | }; |
328 | 337 | ||
@@ -331,7 +340,6 @@ pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionI | |||
331 | } else { | 340 | } else { |
332 | single_file_with_position(code) | 341 | single_file_with_position(code) |
333 | }; | 342 | }; |
334 | let options = CompletionOptions::default(); | ||
335 | let completions = completions(&analysis.db, position, &options).unwrap(); | 343 | let completions = completions(&analysis.db, position, &options).unwrap(); |
336 | let completion_items: Vec<CompletionItem> = completions.into(); | 344 | let completion_items: Vec<CompletionItem> = completions.into(); |
337 | let mut kind_completions: Vec<CompletionItem> = | 345 | let mut kind_completions: Vec<CompletionItem> = |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 3dc56e4a3..5fc8b483c 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -307,12 +307,22 @@ mod tests { | |||
307 | use insta::assert_debug_snapshot; | 307 | use insta::assert_debug_snapshot; |
308 | use test_utils::covers; | 308 | use test_utils::covers; |
309 | 309 | ||
310 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 310 | use crate::completion::{ |
311 | do_completion, do_completion_with_options, CompletionItem, CompletionKind, | ||
312 | CompletionOptions, | ||
313 | }; | ||
311 | 314 | ||
312 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { | 315 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { |
313 | do_completion(ra_fixture, CompletionKind::Reference) | 316 | do_completion(ra_fixture, CompletionKind::Reference) |
314 | } | 317 | } |
315 | 318 | ||
319 | fn do_reference_completion_with_options( | ||
320 | ra_fixture: &str, | ||
321 | options: CompletionOptions, | ||
322 | ) -> Vec<CompletionItem> { | ||
323 | do_completion_with_options(ra_fixture, CompletionKind::Reference, &options) | ||
324 | } | ||
325 | |||
316 | #[test] | 326 | #[test] |
317 | fn enum_detail_includes_names_for_record() { | 327 | fn enum_detail_includes_names_for_record() { |
318 | assert_debug_snapshot!( | 328 | assert_debug_snapshot!( |
@@ -533,7 +543,7 @@ mod tests { | |||
533 | } | 543 | } |
534 | 544 | ||
535 | #[test] | 545 | #[test] |
536 | fn parens_for_method_call() { | 546 | fn arg_snippets_for_method_call() { |
537 | assert_debug_snapshot!( | 547 | assert_debug_snapshot!( |
538 | do_reference_completion( | 548 | do_reference_completion( |
539 | r" | 549 | r" |
@@ -563,6 +573,40 @@ mod tests { | |||
563 | } | 573 | } |
564 | 574 | ||
565 | #[test] | 575 | #[test] |
576 | fn no_arg_snippets_for_method_call() { | ||
577 | assert_debug_snapshot!( | ||
578 | do_reference_completion_with_options( | ||
579 | r" | ||
580 | struct S {} | ||
581 | impl S { | ||
582 | fn foo(&self, x: i32) {} | ||
583 | } | ||
584 | fn bar(s: &S) { | ||
585 | s.f<|> | ||
586 | } | ||
587 | ", | ||
588 | CompletionOptions { | ||
589 | add_call_argument_snippets: false, | ||
590 | .. Default::default() | ||
591 | } | ||
592 | ), | ||
593 | @r###" | ||
594 | [ | ||
595 | CompletionItem { | ||
596 | label: "foo(…)", | ||
597 | source_range: [171; 172), | ||
598 | delete: [171; 172), | ||
599 | insert: "foo($0)", | ||
600 | kind: Method, | ||
601 | lookup: "foo", | ||
602 | detail: "fn foo(&self, x: i32)", | ||
603 | }, | ||
604 | ] | ||
605 | "### | ||
606 | ) | ||
607 | } | ||
608 | |||
609 | #[test] | ||
566 | fn dont_render_function_parens_in_use_item() { | 610 | fn dont_render_function_parens_in_use_item() { |
567 | assert_debug_snapshot!( | 611 | assert_debug_snapshot!( |
568 | do_reference_completion( | 612 | do_reference_completion( |