aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-03 22:13:22 +0100
committerAleksey Kladov <[email protected]>2020-07-03 22:15:44 +0100
commit9f9b38bdb47f6301fc01287fbe8dc1256c44fe08 (patch)
tree802521f357257f38db18738059457a77387ea70c /crates/ra_ide/src/completion
parenta095cdb87912e0174341121542af2d4a01d7d8cd (diff)
Cleanup presentation tests
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs193
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs12
2 files changed, 59 insertions, 146 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index bd274bd74..f472b9529 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -460,7 +460,7 @@ mod tests {
460 use test_utils::mark; 460 use test_utils::mark;
461 461
462 use crate::completion::{ 462 use crate::completion::{
463 test_utils::{do_completion, do_completion_with_options}, 463 test_utils::{check_edit, do_completion, do_completion_with_options},
464 CompletionConfig, CompletionItem, CompletionKind, 464 CompletionConfig, CompletionItem, CompletionKind,
465 }; 465 };
466 466
@@ -636,150 +636,59 @@ fn foo() {
636 #[test] 636 #[test]
637 fn inserts_parens_for_function_calls() { 637 fn inserts_parens_for_function_calls() {
638 mark::check!(inserts_parens_for_function_calls); 638 mark::check!(inserts_parens_for_function_calls);
639 assert_debug_snapshot!( 639 check_edit(
640 do_reference_completion( 640 "no_args",
641 r" 641 r#"
642 fn no_args() {} 642fn no_args() {}
643 fn main() { no_<|> } 643fn main() { no_<|> }
644 " 644"#,
645 ), 645 r#"
646 @r###" 646fn no_args() {}
647 [ 647fn main() { no_args()$0 }
648 CompletionItem { 648"#,
649 label: "main()",
650 source_range: 28..31,
651 delete: 28..31,
652 insert: "main()$0",
653 kind: Function,
654 lookup: "main",
655 detail: "fn main()",
656 },
657 CompletionItem {
658 label: "no_args()",
659 source_range: 28..31,
660 delete: 28..31,
661 insert: "no_args()$0",
662 kind: Function,
663 lookup: "no_args",
664 detail: "fn no_args()",
665 },
666 ]
667 "###
668 );
669 assert_debug_snapshot!(
670 do_reference_completion(
671 r"
672 fn with_args(x: i32, y: String) {}
673 fn main() { with_<|> }
674 "
675 ),
676 @r###"
677 [
678 CompletionItem {
679 label: "main()",
680 source_range: 47..52,
681 delete: 47..52,
682 insert: "main()$0",
683 kind: Function,
684 lookup: "main",
685 detail: "fn main()",
686 },
687 CompletionItem {
688 label: "with_args(…)",
689 source_range: 47..52,
690 delete: 47..52,
691 insert: "with_args(${1:x}, ${2:y})$0",
692 kind: Function,
693 lookup: "with_args",
694 detail: "fn with_args(x: i32, y: String)",
695 trigger_call_info: true,
696 },
697 ]
698 "###
699 ); 649 );
700 assert_debug_snapshot!( 650 check_edit(
701 do_reference_completion( 651 "with_args",
702 r" 652 r#"
703 fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String) {} 653fn with_args(x: i32, y: String) {}
704 fn main() { with_<|> } 654fn main() { with_<|> }
705 " 655"#,
706 ), 656 r#"
707 @r###" 657fn with_args(x: i32, y: String) {}
708 [ 658fn main() { with_args(${1:x}, ${2:y})$0 }
709 CompletionItem { 659"#,
710 label: "main()",
711 source_range: 77..82,
712 delete: 77..82,
713 insert: "main()$0",
714 kind: Function,
715 lookup: "main",
716 detail: "fn main()",
717 },
718 CompletionItem {
719 label: "with_ignored_args(…)",
720 source_range: 77..82,
721 delete: 77..82,
722 insert: "with_ignored_args(${1:foo}, ${2:bar}, ${3:ho_ge_})$0",
723 kind: Function,
724 lookup: "with_ignored_args",
725 detail: "fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String)",
726 trigger_call_info: true,
727 },
728 ]
729 "###
730 ); 660 );
731 assert_debug_snapshot!( 661 check_edit(
732 do_reference_completion( 662 "foo",
733 r" 663 r#"
734 struct S {} 664struct S;
735 impl S { 665impl S {
736 fn foo(&self) {} 666 fn foo(&self) {}
737 } 667}
738 fn bar(s: &S) { 668fn bar(s: &S) { s.f<|> }
739 s.f<|> 669"#,
740 } 670 r#"
741 " 671struct S;
742 ), 672impl S {
743 @r###" 673 fn foo(&self) {}
744 [ 674}
745 CompletionItem { 675fn bar(s: &S) { s.foo()$0 }
746 label: "foo()", 676"#,
747 source_range: 66..67,
748 delete: 66..67,
749 insert: "foo()$0",
750 kind: Method,
751 lookup: "foo",
752 detail: "fn foo(&self)",
753 },
754 ]
755 "###
756 ); 677 );
757 assert_debug_snapshot!( 678 }
758 do_reference_completion( 679
759 r" 680 #[test]
760 struct S {} 681 fn strips_underscores_from_args() {
761 impl S { 682 check_edit(
762 fn foo_ignored_args(&self, _a: bool, b: i32) {} 683 "foo",
763 } 684 r#"
764 fn bar(s: &S) { 685fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
765 s.f<|> 686fn main() { f<|> }
766 } 687"#,
767 " 688 r#"
768 ), 689fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
769 @r###" 690fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
770 [ 691"#,
771 CompletionItem {
772 label: "foo_ignored_args(…)",
773 source_range: 97..98,
774 delete: 97..98,
775 insert: "foo_ignored_args(${1:a}, ${2:b})$0",
776 kind: Method,
777 lookup: "foo_ignored_args",
778 detail: "fn foo_ignored_args(&self, _a: bool, b: i32)",
779 trigger_call_info: true,
780 },
781 ]
782 "###
783 ); 692 );
784 } 693 }
785 694
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index 9c036eac7..f25190241 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -3,7 +3,7 @@
3use hir::Semantics; 3use hir::Semantics;
4use itertools::Itertools; 4use itertools::Itertools;
5use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; 5use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
6use stdx::format_to; 6use stdx::{format_to, trim_indent};
7use test_utils::assert_eq_text; 7use test_utils::assert_eq_text;
8 8
9use crate::{ 9use crate::{
@@ -57,14 +57,18 @@ pub(crate) fn completion_list_with_options(
57} 57}
58 58
59pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 59pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
60 let ra_fixture_after = trim_indent(ra_fixture_after);
60 let (analysis, position) = analysis_and_position(ra_fixture_before); 61 let (analysis, position) = analysis_and_position(ra_fixture_before);
61 let completions: Vec<CompletionItem> = 62 let completions: Vec<CompletionItem> =
62 analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into(); 63 analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
63 let (completion,) = 64 let (completion,) = completions
64 completions.into_iter().filter(|it| it.label() == what).collect_tuple().unwrap(); 65 .iter()
66 .filter(|it| it.lookup() == what)
67 .collect_tuple()
68 .unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions));
65 let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); 69 let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
66 completion.text_edit().apply(&mut actual); 70 completion.text_edit().apply(&mut actual);
67 assert_eq_text!(ra_fixture_after, &actual) 71 assert_eq_text!(&ra_fixture_after, &actual)
68} 72}
69 73
70pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { 74pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {