aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs35
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs157
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs32
-rw-r--r--crates/ide_completion/src/tests.rs1
-rw-r--r--crates/ide_completion/src/tests/use_tree.rs261
5 files changed, 262 insertions, 224 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 73bbc4345..b6f06a44f 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -200,41 +200,6 @@ mod tests {
200 } 200 }
201 201
202 #[test] 202 #[test]
203 fn test_keywords_in_use_stmt() {
204 check(
205 r"use $0",
206 expect![[r#"
207 kw crate::
208 kw self
209 kw super::
210 "#]],
211 );
212
213 // FIXME: `self` shouldn't be shown here and the check below
214 check(
215 r"use a::$0",
216 expect![[r#"
217 kw self
218 "#]],
219 );
220
221 check(
222 r"use super::$0",
223 expect![[r#"
224 kw self
225 kw super::
226 "#]],
227 );
228
229 check(
230 r"use a::{b, $0}",
231 expect![[r#"
232 kw self
233 "#]],
234 );
235 }
236
237 #[test]
238 fn test_keywords_in_function() { 203 fn test_keywords_in_function() {
239 check( 204 check(
240 r"fn quux() { $0 }", 205 r"fn quux() { $0 }",
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index 9432caa22..5b49868e4 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -213,12 +213,6 @@ mod tests {
213 } 213 }
214 214
215 #[test] 215 #[test]
216 fn dont_complete_current_use() {
217 cov_mark::check!(dont_complete_current_use);
218 check(r#"use self::foo$0;"#, expect![[""]]);
219 }
220
221 #[test]
222 fn dont_complete_values_in_type_pos() { 216 fn dont_complete_values_in_type_pos() {
223 check( 217 check(
224 r#" 218 r#"
@@ -249,20 +243,6 @@ fn foo() {
249 } 243 }
250 244
251 #[test] 245 #[test]
252 fn dont_complete_current_use_in_braces_with_glob() {
253 check(
254 r#"
255mod foo { pub struct S; }
256use self::{foo::*, bar$0};
257"#,
258 expect![[r#"
259 st S
260 md foo
261 "#]],
262 );
263 }
264
265 #[test]
266 fn dont_complete_primitive_in_use() { 246 fn dont_complete_primitive_in_use() {
267 check_builtin(r#"use self::$0;"#, expect![[""]]); 247 check_builtin(r#"use self::$0;"#, expect![[""]]);
268 } 248 }
@@ -299,108 +279,6 @@ use self::{foo::*, bar$0};
299 } 279 }
300 280
301 #[test] 281 #[test]
302 fn completes_mod_with_same_name_as_function() {
303 check(
304 r#"
305use self::my::$0;
306
307mod my { pub struct Bar; }
308fn my() {}
309"#,
310 expect![[r#"
311 st Bar
312 "#]],
313 );
314 }
315
316 #[test]
317 fn filters_visibility() {
318 check(
319 r#"
320use self::my::$0;
321
322mod my {
323 struct Bar;
324 pub struct Foo;
325 pub use Bar as PublicBar;
326}
327"#,
328 expect![[r#"
329 st Foo
330 st PublicBar
331 "#]],
332 );
333 }
334
335 #[test]
336 fn completes_use_item_starting_with_self() {
337 check(
338 r#"
339use self::m::$0;
340
341mod m { pub struct Bar; }
342"#,
343 expect![[r#"
344 st Bar
345 "#]],
346 );
347 }
348
349 #[test]
350 fn completes_use_item_starting_with_crate() {
351 check(
352 r#"
353//- /lib.rs
354mod foo;
355struct Spam;
356//- /foo.rs
357use crate::Sp$0
358"#,
359 expect![[r#"
360 md foo
361 st Spam
362 "#]],
363 );
364 }
365
366 #[test]
367 fn completes_nested_use_tree() {
368 check(
369 r#"
370//- /lib.rs
371mod foo;
372struct Spam;
373//- /foo.rs
374use crate::{Sp$0};
375"#,
376 expect![[r#"
377 md foo
378 st Spam
379 "#]],
380 );
381 }
382
383 #[test]
384 fn completes_deeply_nested_use_tree() {
385 check(
386 r#"
387//- /lib.rs
388mod foo;
389pub mod bar {
390 pub mod baz {
391 pub struct Spam;
392 }
393}
394//- /foo.rs
395use crate::{bar::{baz::Sp$0}};
396"#,
397 expect![[r#"
398 st Spam
399 "#]],
400 );
401 }
402
403 #[test]
404 fn completes_enum_variant() { 282 fn completes_enum_variant() {
405 check( 283 check(
406 r#" 284 r#"
@@ -497,22 +375,6 @@ fn foo() { let _ = U::$0 }
497 } 375 }
498 376
499 #[test] 377 #[test]
500 fn completes_use_paths_across_crates() {
501 check(
502 r#"
503//- /main.rs crate:main deps:foo
504use foo::$0;
505
506//- /foo/lib.rs crate:foo
507pub mod bar { pub struct S; }
508"#,
509 expect![[r#"
510 md bar
511 "#]],
512 );
513 }
514
515 #[test]
516 fn completes_trait_associated_method_1() { 378 fn completes_trait_associated_method_1() {
517 check( 379 check(
518 r#" 380 r#"
@@ -714,25 +576,6 @@ impl MyStruct {
714 } 576 }
715 577
716 #[test] 578 #[test]
717 fn test_super_super_completion() {
718 check(
719 r#"
720mod a {
721 const A: usize = 0;
722 mod b {
723 const B: usize = 0;
724 mod c { use super::super::$0 }
725 }
726}
727"#,
728 expect![[r#"
729 md b
730 ct A
731 "#]],
732 );
733 }
734
735 #[test]
736 fn completes_reexported_items_under_correct_name() { 579 fn completes_reexported_items_under_correct_name() {
737 check( 580 check(
738 r#" 581 r#"
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 2868d9b18..83b9148b3 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -130,22 +130,6 @@ fn foo() {
130 } 130 }
131 131
132 #[test] 132 #[test]
133 fn only_completes_modules_in_import() {
134 cov_mark::check!(only_completes_modules_in_import);
135 check(
136 r#"
137use f$0
138
139struct Foo;
140mod foo {}
141"#,
142 expect![[r#"
143 md foo
144 "#]],
145 );
146 }
147
148 #[test]
149 fn bind_pat_and_path_ignore_at() { 133 fn bind_pat_and_path_ignore_at() {
150 check( 134 check(
151 r#" 135 r#"
@@ -359,22 +343,6 @@ fn _alpha() {}
359 } 343 }
360 344
361 #[test] 345 #[test]
362 fn completes_extern_prelude() {
363 check(
364 r#"
365//- /lib.rs crate:main deps:other_crate
366use $0;
367
368//- /other_crate/lib.rs crate:other_crate
369// nothing here
370"#,
371 expect![[r#"
372 md other_crate
373 "#]],
374 );
375 }
376
377 #[test]
378 fn completes_module_items_in_nested_modules() { 346 fn completes_module_items_in_nested_modules() {
379 check( 347 check(
380 r#" 348 r#"
diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs
index 1495924ea..89c7fb524 100644
--- a/crates/ide_completion/src/tests.rs
+++ b/crates/ide_completion/src/tests.rs
@@ -1,4 +1,5 @@
1mod item_list; 1mod item_list;
2mod use_tree;
2 3
3use hir::{PrefixKind, Semantics}; 4use hir::{PrefixKind, Semantics};
4use ide_db::{ 5use ide_db::{
diff --git a/crates/ide_completion/src/tests/use_tree.rs b/crates/ide_completion/src/tests/use_tree.rs
new file mode 100644
index 000000000..156ca244d
--- /dev/null
+++ b/crates/ide_completion/src/tests/use_tree.rs
@@ -0,0 +1,261 @@
1use expect_test::{expect, Expect};
2
3use crate::tests::completion_list;
4
5fn check(ra_fixture: &str, expect: Expect) {
6 let actual = completion_list(ra_fixture);
7 expect.assert_eq(&actual)
8}
9
10#[test]
11fn use_tree_start() {
12 cov_mark::check!(only_completes_modules_in_import);
13 check(
14 r#"
15//- /lib.rs crate:main deps:other_crate
16use f$0
17
18struct Foo;
19mod foo {}
20//- /other_crate/lib.rs crate:other_crate
21// nothing here
22"#,
23 // FIXME: self in this case should also get the colons
24 expect![[r#"
25 kw crate::
26 kw self
27 kw super::
28 md foo
29 md other_crate
30 "#]],
31 );
32}
33
34#[test]
35fn dont_complete_current_use() {
36 cov_mark::check!(dont_complete_current_use);
37 // FIXME: self shouldn't be here
38 check(
39 r#"use self::foo$0;"#,
40 expect![[r#"
41 kw self
42 "#]],
43 );
44 check(
45 r#"
46mod foo { pub struct S; }
47use self::{foo::*, bar$0};
48"#,
49 expect![[r#"
50 kw self
51 st S
52 md foo
53 "#]],
54 );
55}
56
57#[test]
58fn nested_use_tree() {
59 // FIXME: self shouldn't be here
60 check(
61 r#"
62mod foo {
63 pub mod bar {
64 pub struct FooBar;
65 }
66}
67use foo::{bar::$0}
68"#,
69 expect![[r#"
70 kw self
71 st FooBar
72 "#]],
73 );
74 check(
75 r#"
76mod foo {
77 pub mod bar {
78 pub struct FooBar;
79 }
80}
81use foo::{$0}
82"#,
83 expect![[r#"
84 kw self
85 md bar
86 "#]],
87 );
88}
89
90#[test]
91fn deeply_nested_use_tree() {
92 // FIXME: self shouldn't be here
93 check(
94 r#"
95mod foo {
96 pub mod bar {
97 pub mod baz {
98 pub struct FooBarBaz;
99 }
100 }
101}
102use foo::{bar::{baz::$0}}
103"#,
104 expect![[r#"
105 kw self
106 st FooBarBaz
107 "#]],
108 );
109 check(
110 r#"
111mod foo {
112 pub mod bar {
113 pub mod baz {
114 pub struct FooBarBaz;
115 }
116 }
117}
118use foo::{bar::{$0}}
119"#,
120 expect![[r#"
121 kw self
122 md baz
123 "#]],
124 );
125}
126
127#[test]
128fn plain_qualified_use_tree() {
129 // FIXME: self shouldn't be here
130 check(
131 r#"
132use foo::$0
133
134mod foo {
135 struct Private;
136 pub struct Foo;
137}
138struct Bar;
139"#,
140 expect![[r#"
141 kw self
142 st Foo
143 "#]],
144 );
145}
146
147#[test]
148fn self_qualified_use_tree() {
149 // FIXME: self shouldn't be here
150 check(
151 r#"
152use self::$0
153
154mod foo {}
155struct Bar;
156"#,
157 expect![[r#"
158 kw self
159 md foo
160 st Bar
161 "#]],
162 );
163}
164
165#[test]
166fn super_qualified_use_tree() {
167 // FIXME: self shouldn't be here
168 check(
169 r#"
170mod bar {
171 use super::$0
172}
173
174mod foo {}
175struct Bar;
176"#,
177 expect![[r#"
178 kw self
179 kw super::
180 st Bar
181 md bar
182 md foo
183 "#]],
184 );
185}
186
187#[test]
188fn super_super_qualified_use_tree() {
189 // FIXME: self shouldn't be here
190 check(
191 r#"
192mod a {
193 const A: usize = 0;
194 mod b {
195 const B: usize = 0;
196 mod c { use super::super::$0 }
197 }
198}
199"#,
200 expect![[r#"
201 kw self
202 kw super::
203 md b
204 ct A
205 "#]],
206 );
207}
208
209#[test]
210fn crate_qualified_use_tree() {
211 // FIXME: self shouldn't be here
212 check(
213 r#"
214use crate::$0
215
216mod foo {}
217struct Bar;
218"#,
219 expect![[r#"
220 kw self
221 md foo
222 st Bar
223 "#]],
224 );
225}
226
227#[test]
228fn extern_crate_qualified_use_tree() {
229 // FIXME: self shouldn't be here
230 check(
231 r#"
232//- /lib.rs crate:main deps:other_crate
233use other_crate::$0
234//- /other_crate/lib.rs crate:other_crate
235pub struct Foo;
236pub mod foo {}
237"#,
238 expect![[r#"
239 kw self
240 st Foo
241 md foo
242 "#]],
243 );
244}
245
246#[test]
247fn pub_use_tree() {
248 check(
249 r#"
250pub struct X;
251pub mod bar {}
252pub use $0;
253"#,
254 expect![[r#"
255 kw crate::
256 kw self
257 kw super::
258 md bar
259 "#]],
260 );
261}