aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs163
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap7
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap7
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap24
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap27
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap24
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap16
10 files changed, 136 insertions, 180 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 18b2d68d5..c093d5cfb 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -55,29 +55,41 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
55 55
56#[cfg(test)] 56#[cfg(test)]
57mod tests { 57mod tests {
58 use crate::completion::{check_completion, CompletionKind}; 58 use crate::completion::{do_completion, CompletionKind, CompletionItem};
59 use insta::assert_debug_snapshot_matches;
59 60
60 fn check_ref_completion(name: &str, code: &str) { 61 fn do_ref_completion(code: &str) -> Vec<CompletionItem> {
61 check_completion(name, code, CompletionKind::Reference); 62 do_completion(code, CompletionKind::Reference)
62 } 63 }
63 64
64 #[test] 65 #[test]
65 fn test_struct_field_completion() { 66 fn test_struct_field_completion() {
66 check_ref_completion( 67 assert_debug_snapshot_matches!(
67 "struct_field_completion", 68 do_ref_completion(
68 r" 69 r"
69 struct A { the_field: u32 } 70 struct A { the_field: u32 }
70 fn foo(a: A) { 71 fn foo(a: A) {
71 a.<|> 72 a.<|>
72 } 73 }
73 ", 74 ",
75 ),
76 @r###"[
77 CompletionItem {
78 label: "the_field",
79 source_range: [94; 94),
80 delete: [94; 94),
81 insert: "the_field",
82 kind: Field,
83 detail: "u32"
84 }
85]"###
74 ); 86 );
75 } 87 }
76 88
77 #[test] 89 #[test]
78 fn test_struct_field_completion_self() { 90 fn test_struct_field_completion_self() {
79 check_ref_completion( 91 assert_debug_snapshot_matches!(
80 "struct_field_completion_self", 92 do_ref_completion(
81 r" 93 r"
82 struct A { 94 struct A {
83 /// This is the_field 95 /// This is the_field
@@ -89,13 +101,35 @@ mod tests {
89 } 101 }
90 } 102 }
91 ", 103 ",
104 ),
105 @r###"[
106 CompletionItem {
107 label: "foo",
108 source_range: [187; 187),
109 delete: [187; 187),
110 insert: "foo()$0",
111 kind: Method,
112 detail: "fn foo(self)"
113 },
114 CompletionItem {
115 label: "the_field",
116 source_range: [187; 187),
117 delete: [187; 187),
118 insert: "the_field",
119 kind: Field,
120 detail: "(u32,)",
121 documentation: Documentation(
122 "This is the_field"
123 )
124 }
125]"###
92 ); 126 );
93 } 127 }
94 128
95 #[test] 129 #[test]
96 fn test_struct_field_completion_autoderef() { 130 fn test_struct_field_completion_autoderef() {
97 check_ref_completion( 131 assert_debug_snapshot_matches!(
98 "struct_field_completion_autoderef", 132 do_ref_completion(
99 r" 133 r"
100 struct A { the_field: (u32, i32) } 134 struct A { the_field: (u32, i32) }
101 impl A { 135 impl A {
@@ -104,26 +138,47 @@ mod tests {
104 } 138 }
105 } 139 }
106 ", 140 ",
141 ),
142 @r###"[
143 CompletionItem {
144 label: "foo",
145 source_range: [126; 126),
146 delete: [126; 126),
147 insert: "foo()$0",
148 kind: Method,
149 detail: "fn foo(&self)"
150 },
151 CompletionItem {
152 label: "the_field",
153 source_range: [126; 126),
154 delete: [126; 126),
155 insert: "the_field",
156 kind: Field,
157 detail: "(u32, i32)"
158 }
159]"###
107 ); 160 );
108 } 161 }
109 162
110 #[test] 163 #[test]
111 fn test_no_struct_field_completion_for_method_call() { 164 fn test_no_struct_field_completion_for_method_call() {
112 check_ref_completion( 165 assert_debug_snapshot_matches!(
113 "no_struct_field_completion_for_method_call", 166 do_ref_completion(
114 r" 167 r"
115 struct A { the_field: u32 } 168 struct A { the_field: u32 }
116 fn foo(a: A) { 169 fn foo(a: A) {
117 a.<|>() 170 a.<|>()
118 } 171 }
119 ", 172 ",
173 ),
174 @"[]"
120 ); 175 );
121 } 176 }
122 177
123 #[test] 178 #[test]
124 fn test_method_completion() { 179 fn test_method_completion() {
125 check_ref_completion( 180 assert_debug_snapshot_matches!(
126 "method_completion", 181 do_ref_completion(
127 r" 182 r"
128 struct A {} 183 struct A {}
129 impl A { 184 impl A {
@@ -133,13 +188,24 @@ mod tests {
133 a.<|> 188 a.<|>
134 } 189 }
135 ", 190 ",
191 ),
192 @r###"[
193 CompletionItem {
194 label: "the_method",
195 source_range: [144; 144),
196 delete: [144; 144),
197 insert: "the_method()$0",
198 kind: Method,
199 detail: "fn the_method(&self)"
200 }
201]"###
136 ); 202 );
137 } 203 }
138 204
139 #[test] 205 #[test]
140 fn test_no_non_self_method() { 206 fn test_no_non_self_method() {
141 check_ref_completion( 207 assert_debug_snapshot_matches!(
142 "no_non_self_method", 208 do_ref_completion(
143 r" 209 r"
144 struct A {} 210 struct A {}
145 impl A { 211 impl A {
@@ -149,13 +215,15 @@ mod tests {
149 a.<|> 215 a.<|>
150 } 216 }
151 ", 217 ",
218 ),
219 @"[]"
152 ); 220 );
153 } 221 }
154 222
155 #[test] 223 #[test]
156 fn test_method_attr_filtering() { 224 fn test_method_attr_filtering() {
157 check_ref_completion( 225 assert_debug_snapshot_matches!(
158 "method_attr_filtering", 226 do_ref_completion(
159 r" 227 r"
160 struct A {} 228 struct A {}
161 impl A { 229 impl A {
@@ -169,26 +237,56 @@ mod tests {
169 a.<|> 237 a.<|>
170 } 238 }
171 ", 239 ",
240 ),
241 @r###"[
242 CompletionItem {
243 label: "the_method",
244 source_range: [249; 249),
245 delete: [249; 249),
246 insert: "the_method()$0",
247 kind: Method,
248 detail: "fn the_method(&self)"
249 }
250]"###
172 ); 251 );
173 } 252 }
174 253
175 #[test] 254 #[test]
176 fn test_tuple_field_completion() { 255 fn test_tuple_field_completion() {
177 check_ref_completion( 256 assert_debug_snapshot_matches!(
178 "tuple_field_completion", 257 do_ref_completion(
179 r" 258 r"
180 fn foo() { 259 fn foo() {
181 let b = (0, 3.14); 260 let b = (0, 3.14);
182 b.<|> 261 b.<|>
183 } 262 }
184 ", 263 ",
264 ),
265 @r###"[
266 CompletionItem {
267 label: "0",
268 source_range: [75; 75),
269 delete: [75; 75),
270 insert: "0",
271 kind: Field,
272 detail: "i32"
273 },
274 CompletionItem {
275 label: "1",
276 source_range: [75; 75),
277 delete: [75; 75),
278 insert: "1",
279 kind: Field,
280 detail: "f64"
281 }
282]"###
185 ); 283 );
186 } 284 }
187 285
188 #[test] 286 #[test]
189 fn test_tuple_field_inference() { 287 fn test_tuple_field_inference() {
190 check_ref_completion( 288 assert_debug_snapshot_matches!(
191 "tuple_field_inference", 289 do_ref_completion(
192 r" 290 r"
193 pub struct S; 291 pub struct S;
194 impl S { 292 impl S {
@@ -204,6 +302,17 @@ mod tests {
204 } 302 }
205 } 303 }
206 ", 304 ",
305 ),
306 @r###"[
307 CompletionItem {
308 label: "blah",
309 source_range: [299; 300),
310 delete: [299; 300),
311 insert: "blah()$0",
312 kind: Method,
313 detail: "pub fn blah(&self)"
314 }
315]"###
207 ); 316 );
208 } 317 }
209} 318}
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap
deleted file mode 100644
index ce8af2159..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-18T09:22:23.941335305Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "the_method",
10 source_range: [249; 249),
11 delete: [249; 249),
12 insert: "the_method()$0",
13 kind: Method,
14 detail: "fn the_method(&self)"
15 }
16]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap
deleted file mode 100644
index 41a10de14..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-18T09:22:23.939676100Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "the_method",
10 source_range: [144; 144),
11 delete: [144; 144),
12 insert: "the_method()$0",
13 kind: Method,
14 detail: "fn the_method(&self)"
15 }
16]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap
deleted file mode 100644
index 7cc827532..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap
+++ /dev/null
@@ -1,7 +0,0 @@
1---
2created: "2019-01-22T14:45:00.552379600+00:00"
3creator: [email protected]
4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
6---
7[]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap
deleted file mode 100644
index 7cc827532..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap
+++ /dev/null
@@ -1,7 +0,0 @@
1---
2created: "2019-01-22T14:45:00.552379600+00:00"
3creator: [email protected]
4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
6---
7[]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap
deleted file mode 100644
index 58271b873..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-02-18T09:22:23.939645902Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "the_field",
10 source_range: [85; 85),
11 delete: [85; 85),
12 insert: "the_field",
13 kind: Field,
14 detail: "u32"
15 }
16]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap
deleted file mode 100644
index b38867b81..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-02-18T09:22:23.940872916Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "foo",
10 source_range: [126; 126),
11 delete: [126; 126),
12 insert: "foo()$0",
13 kind: Method,
14 detail: "fn foo(&self)"
15 },
16 CompletionItem {
17 label: "the_field",
18 source_range: [126; 126),
19 delete: [126; 126),
20 insert: "the_field",
21 kind: Field,
22 detail: "(u32, i32)"
23 }
24]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap
deleted file mode 100644
index 8e5cab43e..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap
+++ /dev/null
@@ -1,27 +0,0 @@
1---
2created: "2019-02-18T09:22:23.940872918Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "foo",
10 source_range: [187; 187),
11 delete: [187; 187),
12 insert: "foo()$0",
13 kind: Method,
14 detail: "fn foo(self)"
15 },
16 CompletionItem {
17 label: "the_field",
18 source_range: [187; 187),
19 delete: [187; 187),
20 insert: "the_field",
21 kind: Field,
22 detail: "(u32,)",
23 documentation: Documentation(
24 "This is the_field"
25 )
26 }
27]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap
deleted file mode 100644
index 3f2780621..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-02-18T09:22:23.939710971Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "0",
10 source_range: [75; 75),
11 delete: [75; 75),
12 insert: "0",
13 kind: Field,
14 detail: "i32"
15 },
16 CompletionItem {
17 label: "1",
18 source_range: [75; 75),
19 delete: [75; 75),
20 insert: "1",
21 kind: Field,
22 detail: "f64"
23 }
24]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap
deleted file mode 100644
index 72c8973b8..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-04-05T23:00:18.283812700Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "blah",
10 source_range: [299; 300),
11 delete: [299; 300),
12 insert: "blah()$0",
13 kind: Method,
14 detail: "pub fn blah(&self)"
15 }
16]