diff options
Diffstat (limited to 'crates/ra_ide/src')
6 files changed, 141 insertions, 183 deletions
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index f5573ddf7..9fb5c050e 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs | |||
@@ -54,85 +54,81 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
54 | 54 | ||
55 | #[cfg(test)] | 55 | #[cfg(test)] |
56 | mod tests { | 56 | mod tests { |
57 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 57 | use expect::{expect, Expect}; |
58 | use insta::assert_debug_snapshot; | ||
59 | 58 | ||
60 | fn do_magic_completion(code: &str) -> Vec<CompletionItem> { | 59 | use crate::completion::{test_utils::do_completion, CompletionKind}; |
61 | do_completion(code, CompletionKind::Magic) | 60 | |
61 | fn check(ra_fixture: &str, expect: Expect) { | ||
62 | let actual = do_completion(ra_fixture, CompletionKind::Magic); | ||
63 | expect.assert_debug_eq(&actual); | ||
62 | } | 64 | } |
63 | 65 | ||
64 | #[test] | 66 | #[test] |
65 | fn test_param_completion_last_param() { | 67 | fn test_param_completion_last_param() { |
66 | assert_debug_snapshot!( | 68 | check( |
67 | do_magic_completion( | 69 | r#" |
68 | r" | 70 | fn foo(file_id: FileId) {} |
69 | fn foo(file_id: FileId) {} | 71 | fn bar(file_id: FileId) {} |
70 | fn bar(file_id: FileId) {} | 72 | fn baz(file<|>) {} |
71 | fn baz(file<|>) {} | 73 | "#, |
72 | ", | 74 | expect![[r#" |
73 | ), | 75 | [ |
74 | @r###" | 76 | CompletionItem { |
75 | [ | 77 | label: "file_id: FileId", |
76 | CompletionItem { | 78 | source_range: 61..65, |
77 | label: "file_id: FileId", | 79 | delete: 61..65, |
78 | source_range: 61..65, | 80 | insert: "file_id: FileId", |
79 | delete: 61..65, | 81 | lookup: "file_id", |
80 | insert: "file_id: FileId", | 82 | }, |
81 | lookup: "file_id", | 83 | ] |
82 | }, | 84 | "#]], |
83 | ] | ||
84 | "### | ||
85 | ); | 85 | ); |
86 | } | 86 | } |
87 | 87 | ||
88 | #[test] | 88 | #[test] |
89 | fn test_param_completion_nth_param() { | 89 | fn test_param_completion_nth_param() { |
90 | assert_debug_snapshot!( | 90 | check( |
91 | do_magic_completion( | 91 | r#" |
92 | r" | 92 | fn foo(file_id: FileId) {} |
93 | fn foo(file_id: FileId) {} | 93 | fn bar(file_id: FileId) {} |
94 | fn bar(file_id: FileId) {} | 94 | fn baz(file<|>, x: i32) {} |
95 | fn baz(file<|>, x: i32) {} | 95 | "#, |
96 | ", | 96 | expect![[r#" |
97 | ), | 97 | [ |
98 | @r###" | 98 | CompletionItem { |
99 | [ | 99 | label: "file_id: FileId", |
100 | CompletionItem { | 100 | source_range: 61..65, |
101 | label: "file_id: FileId", | 101 | delete: 61..65, |
102 | source_range: 61..65, | 102 | insert: "file_id: FileId", |
103 | delete: 61..65, | 103 | lookup: "file_id", |
104 | insert: "file_id: FileId", | 104 | }, |
105 | lookup: "file_id", | 105 | ] |
106 | }, | 106 | "#]], |
107 | ] | ||
108 | "### | ||
109 | ); | 107 | ); |
110 | } | 108 | } |
111 | 109 | ||
112 | #[test] | 110 | #[test] |
113 | fn test_param_completion_trait_param() { | 111 | fn test_param_completion_trait_param() { |
114 | assert_debug_snapshot!( | 112 | check( |
115 | do_magic_completion( | 113 | r#" |
116 | r" | 114 | pub(crate) trait SourceRoot { |
117 | pub(crate) trait SourceRoot { | 115 | pub fn contains(&self, file_id: FileId) -> bool; |
118 | pub fn contains(&self, file_id: FileId) -> bool; | 116 | pub fn module_map(&self) -> &ModuleMap; |
119 | pub fn module_map(&self) -> &ModuleMap; | 117 | pub fn lines(&self, file_id: FileId) -> &LineIndex; |
120 | pub fn lines(&self, file_id: FileId) -> &LineIndex; | 118 | pub fn syntax(&self, file<|>) |
121 | pub fn syntax(&self, file<|>) | 119 | } |
122 | } | 120 | "#, |
123 | ", | 121 | expect![[r#" |
124 | ), | 122 | [ |
125 | @r###" | 123 | CompletionItem { |
126 | [ | 124 | label: "file_id: FileId", |
127 | CompletionItem { | 125 | source_range: 208..212, |
128 | label: "file_id: FileId", | 126 | delete: 208..212, |
129 | source_range: 208..212, | 127 | insert: "file_id: FileId", |
130 | delete: 208..212, | 128 | lookup: "file_id", |
131 | insert: "file_id: FileId", | 129 | }, |
132 | lookup: "file_id", | 130 | ] |
133 | }, | 131 | "#]], |
134 | ] | ||
135 | "### | ||
136 | ); | 132 | ); |
137 | } | 133 | } |
138 | } | 134 | } |
diff --git a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs index 4c33f41d4..d6613ed7b 100644 --- a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs | |||
@@ -15,130 +15,27 @@ pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl | |||
15 | 15 | ||
16 | #[cfg(test)] | 16 | #[cfg(test)] |
17 | mod tests { | 17 | mod tests { |
18 | use insta::assert_debug_snapshot; | 18 | use expect::{expect, Expect}; |
19 | 19 | ||
20 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 20 | use crate::completion::{test_utils::completion_list, CompletionKind}; |
21 | 21 | ||
22 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { | 22 | fn check(ra_fixture: &str, expect: Expect) { |
23 | do_completion(code, CompletionKind::Reference) | 23 | let actual = completion_list(ra_fixture, CompletionKind::Reference); |
24 | expect.assert_eq(&actual) | ||
24 | } | 25 | } |
25 | 26 | ||
26 | #[test] | 27 | #[test] |
27 | fn completes_macros_as_item() { | 28 | fn completes_macros_as_item() { |
28 | assert_debug_snapshot!( | 29 | check( |
29 | do_reference_completion( | 30 | r#" |
30 | " | 31 | macro_rules! foo { () => {} } |
31 | //- /main.rs | 32 | fn foo() {} |
32 | macro_rules! foo { | 33 | |
33 | () => {} | 34 | <|> |
34 | } | 35 | "#, |
35 | 36 | expect![[r#" | |
36 | fn foo() {} | 37 | ma foo!(…) macro_rules! foo |
37 | 38 | "#]], | |
38 | <|> | 39 | ) |
39 | " | ||
40 | ), | ||
41 | @r###" | ||
42 | [ | ||
43 | CompletionItem { | ||
44 | label: "foo!(…)", | ||
45 | source_range: 48..48, | ||
46 | delete: 48..48, | ||
47 | insert: "foo!($0)", | ||
48 | kind: Macro, | ||
49 | detail: "macro_rules! foo", | ||
50 | }, | ||
51 | ] | ||
52 | "### | ||
53 | ); | ||
54 | } | ||
55 | |||
56 | #[test] | ||
57 | fn completes_vec_macros_with_square_brackets() { | ||
58 | assert_debug_snapshot!( | ||
59 | do_reference_completion( | ||
60 | " | ||
61 | //- /main.rs | ||
62 | /// Creates a [`Vec`] containing the arguments. | ||
63 | /// | ||
64 | /// - Create a [`Vec`] containing a given list of elements: | ||
65 | /// | ||
66 | /// ``` | ||
67 | /// let v = vec![1, 2, 3]; | ||
68 | /// assert_eq!(v[0], 1); | ||
69 | /// assert_eq!(v[1], 2); | ||
70 | /// assert_eq!(v[2], 3); | ||
71 | /// ``` | ||
72 | macro_rules! vec { | ||
73 | () => {} | ||
74 | } | ||
75 | |||
76 | fn foo() {} | ||
77 | |||
78 | <|> | ||
79 | " | ||
80 | ), | ||
81 | @r###" | ||
82 | [ | ||
83 | CompletionItem { | ||
84 | label: "vec![…]", | ||
85 | source_range: 282..282, | ||
86 | delete: 282..282, | ||
87 | insert: "vec![$0]", | ||
88 | kind: Macro, | ||
89 | detail: "macro_rules! vec", | ||
90 | documentation: Documentation( | ||
91 | "Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```", | ||
92 | ), | ||
93 | }, | ||
94 | ] | ||
95 | "### | ||
96 | ); | ||
97 | } | ||
98 | |||
99 | #[test] | ||
100 | fn completes_macros_braces_guessing() { | ||
101 | assert_debug_snapshot!( | ||
102 | do_reference_completion( | ||
103 | " | ||
104 | //- /main.rs | ||
105 | /// Foo | ||
106 | /// | ||
107 | /// Not call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`. | ||
108 | /// Call as `let _=foo! { hello world };` | ||
109 | macro_rules! foo { | ||
110 | () => {} | ||
111 | } | ||
112 | |||
113 | fn main() { | ||
114 | <|> | ||
115 | } | ||
116 | " | ||
117 | ), | ||
118 | @r###" | ||
119 | [ | ||
120 | CompletionItem { | ||
121 | label: "foo! {…}", | ||
122 | source_range: 164..164, | ||
123 | delete: 164..164, | ||
124 | insert: "foo! {$0}", | ||
125 | kind: Macro, | ||
126 | detail: "macro_rules! foo", | ||
127 | documentation: Documentation( | ||
128 | "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", | ||
129 | ), | ||
130 | }, | ||
131 | CompletionItem { | ||
132 | label: "main()", | ||
133 | source_range: 164..164, | ||
134 | delete: 164..164, | ||
135 | insert: "main()$0", | ||
136 | kind: Function, | ||
137 | lookup: "main", | ||
138 | detail: "fn main()", | ||
139 | }, | ||
140 | ] | ||
141 | "### | ||
142 | ); | ||
143 | } | 40 | } |
144 | } | 41 | } |
diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index 367e2bbce..9b79e7a09 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs | |||
@@ -130,6 +130,7 @@ mod tests { | |||
130 | delete: 90..90, | 130 | delete: 90..90, |
131 | insert: "m!($0)", | 131 | insert: "m!($0)", |
132 | kind: Macro, | 132 | kind: Macro, |
133 | lookup: "m!", | ||
133 | detail: "macro_rules! m", | 134 | detail: "macro_rules! m", |
134 | }, | 135 | }, |
135 | ] | 136 | ] |
diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index a16866cd2..5175c8afe 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs | |||
@@ -1189,6 +1189,7 @@ mod tests { | |||
1189 | delete: 82..82, | 1189 | delete: 82..82, |
1190 | insert: "foo!($0)", | 1190 | insert: "foo!($0)", |
1191 | kind: Macro, | 1191 | kind: Macro, |
1192 | lookup: "foo!", | ||
1192 | detail: "#[macro_export]\nmacro_rules! foo", | 1193 | detail: "#[macro_export]\nmacro_rules! foo", |
1193 | }, | 1194 | }, |
1194 | CompletionItem { | 1195 | CompletionItem { |
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index a0a04bb58..0d1e9f8ea 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -785,6 +785,7 @@ mod tests { | |||
785 | delete: 256..256, | 785 | delete: 256..256, |
786 | insert: "bar!($0)", | 786 | insert: "bar!($0)", |
787 | kind: Macro, | 787 | kind: Macro, |
788 | lookup: "bar!", | ||
788 | detail: "macro_rules! bar", | 789 | detail: "macro_rules! bar", |
789 | }, | 790 | }, |
790 | CompletionItem { | 791 | CompletionItem { |
@@ -793,6 +794,7 @@ mod tests { | |||
793 | delete: 256..256, | 794 | delete: 256..256, |
794 | insert: "baz!($0)", | 795 | insert: "baz!($0)", |
795 | kind: Macro, | 796 | kind: Macro, |
797 | lookup: "baz!", | ||
796 | detail: "#[macro_export]\nmacro_rules! baz", | 798 | detail: "#[macro_export]\nmacro_rules! baz", |
797 | }, | 799 | }, |
798 | CompletionItem { | 800 | CompletionItem { |
@@ -801,6 +803,7 @@ mod tests { | |||
801 | delete: 256..256, | 803 | delete: 256..256, |
802 | insert: "foo!($0)", | 804 | insert: "foo!($0)", |
803 | kind: Macro, | 805 | kind: Macro, |
806 | lookup: "foo!", | ||
804 | detail: "macro_rules! foo", | 807 | detail: "macro_rules! foo", |
805 | }, | 808 | }, |
806 | CompletionItem { | 809 | CompletionItem { |
@@ -854,6 +857,7 @@ mod tests { | |||
854 | delete: 50..50, | 857 | delete: 50..50, |
855 | insert: "foo!($0)", | 858 | insert: "foo!($0)", |
856 | kind: Macro, | 859 | kind: Macro, |
860 | lookup: "foo!", | ||
857 | detail: "macro_rules! foo", | 861 | detail: "macro_rules! foo", |
858 | }, | 862 | }, |
859 | CompletionItem { | 863 | CompletionItem { |
@@ -893,6 +897,7 @@ mod tests { | |||
893 | delete: 58..58, | 897 | delete: 58..58, |
894 | insert: "foo!($0)", | 898 | insert: "foo!($0)", |
895 | kind: Macro, | 899 | kind: Macro, |
900 | lookup: "foo!", | ||
896 | detail: "macro_rules! foo", | 901 | detail: "macro_rules! foo", |
897 | }, | 902 | }, |
898 | CompletionItem { | 903 | CompletionItem { |
@@ -932,6 +937,7 @@ mod tests { | |||
932 | delete: 51..51, | 937 | delete: 51..51, |
933 | insert: "foo!($0)", | 938 | insert: "foo!($0)", |
934 | kind: Macro, | 939 | kind: Macro, |
940 | lookup: "foo!", | ||
935 | detail: "macro_rules! foo", | 941 | detail: "macro_rules! foo", |
936 | }, | 942 | }, |
937 | CompletionItem { | 943 | CompletionItem { |
@@ -1005,6 +1011,7 @@ mod tests { | |||
1005 | delete: 80..80, | 1011 | delete: 80..80, |
1006 | insert: "m!($0)", | 1012 | insert: "m!($0)", |
1007 | kind: Macro, | 1013 | kind: Macro, |
1014 | lookup: "m!", | ||
1008 | detail: "macro_rules! m", | 1015 | detail: "macro_rules! m", |
1009 | }, | 1016 | }, |
1010 | CompletionItem { | 1017 | CompletionItem { |
@@ -1058,6 +1065,7 @@ mod tests { | |||
1058 | delete: 80..81, | 1065 | delete: 80..81, |
1059 | insert: "m!($0)", | 1066 | insert: "m!($0)", |
1060 | kind: Macro, | 1067 | kind: Macro, |
1068 | lookup: "m!", | ||
1061 | detail: "macro_rules! m", | 1069 | detail: "macro_rules! m", |
1062 | }, | 1070 | }, |
1063 | CompletionItem { | 1071 | CompletionItem { |
@@ -1111,6 +1119,7 @@ mod tests { | |||
1111 | delete: 80..81, | 1119 | delete: 80..81, |
1112 | insert: "m!($0)", | 1120 | insert: "m!($0)", |
1113 | kind: Macro, | 1121 | kind: Macro, |
1122 | lookup: "m!", | ||
1114 | detail: "macro_rules! m", | 1123 | detail: "macro_rules! m", |
1115 | }, | 1124 | }, |
1116 | CompletionItem { | 1125 | CompletionItem { |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index dc391c46b..946bbef7c 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -174,6 +174,7 @@ impl Completions { | |||
174 | builder | 174 | builder |
175 | .insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket)) | 175 | .insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket)) |
176 | .label(format!("{}!{}…{}", name, bra, ket)) | 176 | .label(format!("{}!{}…{}", name, bra, ket)) |
177 | .lookup_by(format!("{}!", name)) | ||
177 | } | 178 | } |
178 | None if needs_bang => builder.insert_text(format!("{}!", name)), | 179 | None if needs_bang => builder.insert_text(format!("{}!", name)), |
179 | _ => { | 180 | _ => { |
@@ -1079,4 +1080,57 @@ fn go(world: &WorldSnapshot) { go(w<|>) } | |||
1079 | "#]], | 1080 | "#]], |
1080 | ); | 1081 | ); |
1081 | } | 1082 | } |
1083 | |||
1084 | #[test] | ||
1085 | fn guesses_macro_braces() { | ||
1086 | check_edit( | ||
1087 | "vec!", | ||
1088 | r#" | ||
1089 | /// Creates a [`Vec`] containing the arguments. | ||
1090 | /// | ||
1091 | /// ``` | ||
1092 | /// let v = vec![1, 2, 3]; | ||
1093 | /// assert_eq!(v[0], 1); | ||
1094 | /// assert_eq!(v[1], 2); | ||
1095 | /// assert_eq!(v[2], 3); | ||
1096 | /// ``` | ||
1097 | macro_rules! vec { () => {} } | ||
1098 | |||
1099 | fn fn main() { v<|> } | ||
1100 | "#, | ||
1101 | r#" | ||
1102 | /// Creates a [`Vec`] containing the arguments. | ||
1103 | /// | ||
1104 | /// ``` | ||
1105 | /// let v = vec![1, 2, 3]; | ||
1106 | /// assert_eq!(v[0], 1); | ||
1107 | /// assert_eq!(v[1], 2); | ||
1108 | /// assert_eq!(v[2], 3); | ||
1109 | /// ``` | ||
1110 | macro_rules! vec { () => {} } | ||
1111 | |||
1112 | fn fn main() { vec![$0] } | ||
1113 | "#, | ||
1114 | ); | ||
1115 | |||
1116 | check_edit( | ||
1117 | "foo!", | ||
1118 | r#" | ||
1119 | /// Foo | ||
1120 | /// | ||
1121 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
1122 | /// call as `let _=foo! { hello world };` | ||
1123 | macro_rules! foo { () => {} } | ||
1124 | fn main() { <|> } | ||
1125 | "#, | ||
1126 | r#" | ||
1127 | /// Foo | ||
1128 | /// | ||
1129 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
1130 | /// call as `let _=foo! { hello world };` | ||
1131 | macro_rules! foo { () => {} } | ||
1132 | fn main() { foo! {$0} } | ||
1133 | "#, | ||
1134 | ) | ||
1135 | } | ||
1082 | } | 1136 | } |