aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs76
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs97
-rw-r--r--crates/ide_completion/src/tests.rs14
-rw-r--r--crates/ide_completion/src/tests/items.rs32
-rw-r--r--crates/ide_completion/src/tests/type_pos.rs185
5 files changed, 198 insertions, 206 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index f5dbd203b..1b8997ecf 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -219,36 +219,6 @@ mod tests {
219 } 219 }
220 220
221 #[test] 221 #[test]
222 fn dont_complete_values_in_type_pos() {
223 check(
224 r#"
225const FOO: () = ();
226static BAR: () = ();
227struct Baz;
228fn foo() {
229 let _: self::$0;
230}
231"#,
232 expect![[r#"
233 st Baz
234 "#]],
235 );
236 }
237
238 #[test]
239 fn dont_complete_enum_variants_in_type_pos() {
240 check(
241 r#"
242enum Foo { Bar }
243fn foo() {
244 let _: Foo::$0;
245}
246"#,
247 expect![[r#""#]],
248 );
249 }
250
251 #[test]
252 fn dont_complete_primitive_in_use() { 222 fn dont_complete_primitive_in_use() {
253 check_builtin(r#"use self::$0;"#, expect![[""]]); 223 check_builtin(r#"use self::$0;"#, expect![[""]]);
254 } 224 }
@@ -259,32 +229,6 @@ fn foo() {
259 } 229 }
260 230
261 #[test] 231 #[test]
262 fn completes_primitives() {
263 check_builtin(
264 r#"fn main() { let _: $0 = 92; }"#,
265 expect![[r#"
266 bt u32
267 bt bool
268 bt u8
269 bt isize
270 bt u16
271 bt u64
272 bt u128
273 bt f32
274 bt i128
275 bt i16
276 bt str
277 bt i64
278 bt char
279 bt f64
280 bt i32
281 bt i8
282 bt usize
283 "#]],
284 );
285 }
286
287 #[test]
288 fn completes_enum_variant() { 232 fn completes_enum_variant() {
289 check( 233 check(
290 r#" 234 r#"
@@ -749,24 +693,4 @@ fn main() {
749 "#]], 693 "#]],
750 ); 694 );
751 } 695 }
752
753 #[test]
754 fn completes_types_and_const_in_arg_list() {
755 check(
756 r#"
757mod foo {
758 pub const CONST: () = ();
759 pub type Type = ();
760}
761
762struct Foo<T>(t);
763
764fn foo(_: Foo<foo::$0>) {}
765"#,
766 expect![[r#"
767 ta Type
768 ct CONST
769 "#]],
770 );
771 }
772} 696}
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 819fa3a43..380c1e079 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -113,28 +113,6 @@ mod tests {
113 } 113 }
114 114
115 #[test] 115 #[test]
116 fn dont_complete_values_in_type_pos() {
117 check(
118 r#"
119const FOO: () = ();
120static BAR: () = ();
121enum Foo {
122 Bar
123}
124struct Baz;
125fn foo() {
126 let local = ();
127 let _: $0;
128}
129"#,
130 expect![[r#"
131 en Foo
132 st Baz
133 "#]],
134 );
135 }
136
137 #[test]
138 fn completes_bindings_from_let() { 116 fn completes_bindings_from_let() {
139 check( 117 check(
140 r#" 118 r#"
@@ -239,29 +217,6 @@ fn main() {
239 } 217 }
240 218
241 #[test] 219 #[test]
242 fn completes_generic_params_in_struct() {
243 check(
244 r#"struct S<T> { x: $0}"#,
245 expect![[r#"
246 sp Self
247 tp T
248 st S<…>
249 "#]],
250 );
251 }
252
253 #[test]
254 fn completes_self_in_enum() {
255 check(
256 r#"enum X { Y($0) }"#,
257 expect![[r#"
258 sp Self
259 en X
260 "#]],
261 );
262 }
263
264 #[test]
265 fn completes_module_items() { 220 fn completes_module_items() {
266 check( 221 check(
267 r#" 222 r#"
@@ -315,19 +270,6 @@ mod m {
315 } 270 }
316 271
317 #[test] 272 #[test]
318 fn completes_return_type() {
319 check(
320 r#"
321struct Foo;
322fn x() -> $0
323"#,
324 expect![[r#"
325 st Foo
326 "#]],
327 );
328 }
329
330 #[test]
331 fn dont_show_both_completions_for_shadowing() { 273 fn dont_show_both_completions_for_shadowing() {
332 check( 274 check(
333 r#" 275 r#"
@@ -509,19 +451,6 @@ fn foo() { $0 }
509 } 451 }
510 452
511 #[test] 453 #[test]
512 fn completes_macros_as_type() {
513 check(
514 r#"
515macro_rules! foo { () => {} }
516fn main() { let x: $0 }
517"#,
518 expect![[r#"
519 ma foo!(…) macro_rules! foo
520 "#]],
521 );
522 }
523
524 #[test]
525 fn completes_macros_as_stmt() { 454 fn completes_macros_as_stmt() {
526 check( 455 check(
527 r#" 456 r#"
@@ -666,30 +595,4 @@ fn f() {}
666 expect![[""]], 595 expect![[""]],
667 ) 596 )
668 } 597 }
669
670 #[test]
671 fn completes_types_and_const_in_arg_list() {
672 check(
673 r#"
674enum Bar {
675 Baz
676}
677trait Foo {
678 type Bar;
679}
680
681const CONST: () = ();
682
683fn foo<T: Foo<$0>, const CONST_PARAM: usize>(_: T) {}
684"#,
685 expect![[r#"
686 ta Bar = type Bar;
687 tp T
688 cp CONST_PARAM
689 tt Foo
690 en Bar
691 ct CONST
692 "#]],
693 );
694 }
695} 598}
diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs
index 7af8c903b..97298ff27 100644
--- a/crates/ide_completion/src/tests.rs
+++ b/crates/ide_completion/src/tests.rs
@@ -8,6 +8,9 @@ mod item_list;
8mod use_tree; 8mod use_tree;
9mod items; 9mod items;
10mod pattern; 10mod pattern;
11mod type_pos;
12
13use std::mem;
11 14
12use hir::{PrefixKind, Semantics}; 15use hir::{PrefixKind, Semantics};
13use ide_db::{ 16use ide_db::{
@@ -46,7 +49,16 @@ pub(crate) fn completion_list(code: &str) -> String {
46} 49}
47 50
48fn completion_list_with_config(config: CompletionConfig, code: &str) -> String { 51fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
49 render_completion_list(get_all_items(config, code)) 52 // filter out all but one builtintype completion for smaller test outputs
53 let items = get_all_items(config, code);
54 let mut bt_seen = false;
55 let items = items
56 .into_iter()
57 .filter(|it| {
58 it.completion_kind != CompletionKind::BuiltinType || !mem::replace(&mut bt_seen, true)
59 })
60 .collect();
61 render_completion_list(items)
50} 62}
51 63
52/// Creates analysis from a multi-file fixture, returns positions marked with $0. 64/// Creates analysis from a multi-file fixture, returns positions marked with $0.
diff --git a/crates/ide_completion/src/tests/items.rs b/crates/ide_completion/src/tests/items.rs
index 8dfb8221b..b98baffd6 100644
--- a/crates/ide_completion/src/tests/items.rs
+++ b/crates/ide_completion/src/tests/items.rs
@@ -35,22 +35,6 @@ impl Tra$0
35 ma foo!(…) #[macro_export] macro_rules! foo 35 ma foo!(…) #[macro_export] macro_rules! foo
36 ma foo!(…) #[macro_export] macro_rules! foo 36 ma foo!(…) #[macro_export] macro_rules! foo
37 bt u32 37 bt u32
38 bt bool
39 bt u8
40 bt isize
41 bt u16
42 bt u64
43 bt u128
44 bt f32
45 bt i128
46 bt i16
47 bt str
48 bt i64
49 bt char
50 bt f64
51 bt i32
52 bt i8
53 bt usize
54 "##]], 38 "##]],
55 ) 39 )
56} 40}
@@ -69,22 +53,6 @@ impl Trait for Str$0
69 ma foo!(…) #[macro_export] macro_rules! foo 53 ma foo!(…) #[macro_export] macro_rules! foo
70 ma foo!(…) #[macro_export] macro_rules! foo 54 ma foo!(…) #[macro_export] macro_rules! foo
71 bt u32 55 bt u32
72 bt bool
73 bt u8
74 bt isize
75 bt u16
76 bt u64
77 bt u128
78 bt f32
79 bt i128
80 bt i16
81 bt str
82 bt i64
83 bt char
84 bt f64
85 bt i32
86 bt i8
87 bt usize
88 "##]], 56 "##]],
89 ) 57 )
90} 58}
diff --git a/crates/ide_completion/src/tests/type_pos.rs b/crates/ide_completion/src/tests/type_pos.rs
new file mode 100644
index 000000000..2bfecdd08
--- /dev/null
+++ b/crates/ide_completion/src/tests/type_pos.rs
@@ -0,0 +1,185 @@
1//! Completions tests for type position.
2use expect_test::{expect, Expect};
3
4use crate::tests::completion_list;
5
6fn check_with(ra_fixture: &str, expect: Expect) {
7 let base = r#"
8enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
9use self::Enum::TupleV;
10mod module {}
11
12trait Trait {}
13static STATIC: Unit = Unit;
14const CONST: Unit = Unit;
15struct Record { field: u32 }
16struct Tuple(u32);
17struct Unit
18macro_rules! makro {}
19"#;
20 let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
21 expect.assert_eq(&actual)
22}
23
24#[test]
25fn record_field_ty() {
26 // FIXME: pub shouldnt show up here
27 check_with(
28 r#"
29struct Foo<'lt, T, const C: usize> {
30 f: $0
31}
32"#,
33 expect![[r#"
34 kw pub(crate)
35 kw pub
36 sp Self
37 tp T
38 tt Trait
39 en Enum
40 st Record
41 st Tuple
42 md module
43 st Foo<…>
44 st Unit
45 ma makro!(…) macro_rules! makro
46 bt u32
47 "#]],
48 )
49}
50
51#[test]
52fn tuple_struct_field() {
53 // FIXME: pub should show up here
54 check_with(
55 r#"
56struct Foo<'lt, T, const C: usize>(f$0);
57"#,
58 expect![[r#"
59 sp Self
60 tp T
61 tt Trait
62 en Enum
63 st Record
64 st Tuple
65 md module
66 st Foo<…>
67 st Unit
68 ma makro!(…) macro_rules! makro
69 bt u32
70 "#]],
71 )
72}
73
74#[test]
75fn fn_return_type() {
76 // FIXME: return shouldnt show up here
77 check_with(
78 r#"
79fn x<'lt, T, const C: usize>() -> $0
80"#,
81 expect![[r#"
82 kw return
83 tp T
84 tt Trait
85 en Enum
86 st Record
87 st Tuple
88 md module
89 st Unit
90 ma makro!(…) macro_rules! makro
91 bt u32
92 "#]],
93 );
94}
95
96#[test]
97fn body_type_pos() {
98 // FIXME: return shouldnt show up here
99 check_with(
100 r#"
101fn foo<'lt, T, const C: usize>() {
102 let local = ();
103 let _: $0;
104}
105"#,
106 expect![[r#"
107 kw return
108 tp T
109 tt Trait
110 en Enum
111 st Record
112 st Tuple
113 md module
114 st Unit
115 ma makro!(…) macro_rules! makro
116 bt u32
117 "#]],
118 );
119 check_with(
120 r#"
121fn foo<'lt, T, const C: usize>() {
122 let local = ();
123 let _: self::$0;
124}
125"#,
126 expect![[r#"
127 tt Trait
128 en Enum
129 st Record
130 st Tuple
131 md module
132 st Unit
133 "#]],
134 );
135}
136
137#[test]
138fn completes_types_and_const_in_arg_list() {
139 // FIXME: return shouldnt show up here
140 // FIXME: we should complete the lifetime here for now
141 check_with(
142 r#"
143trait Trait2 {
144 type Foo;
145}
146
147fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
148"#,
149 expect![[r#"
150 kw return
151 ta Foo = type Foo;
152 tp T
153 cp CONST_PARAM
154 tt Trait
155 en Enum
156 st Record
157 st Tuple
158 tt Trait2
159 md module
160 st Unit
161 ct CONST
162 ma makro!(…) macro_rules! makro
163 bt u32
164 "#]],
165 );
166 check_with(
167 r#"
168trait Trait2 {
169 type Foo;
170}
171
172fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
173 "#,
174 expect![[r#"
175 tt Trait
176 en Enum
177 st Record
178 st Tuple
179 tt Trait2
180 md module
181 st Unit
182 ct CONST
183 "#]],
184 );
185}