diff options
author | Lukas Wirth <[email protected]> | 2021-06-08 19:27:25 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-06-08 19:27:25 +0100 |
commit | 1a26af15ef190bf605d3a04005aea02664815fb0 (patch) | |
tree | 64a1a96c92439dd6a8d39923d0e4309469fd0363 /crates/ide_completion | |
parent | 1d74ef1d989b3d37f3f08d32e88670ee0f1f7ab6 (diff) |
Add tests checking no value completion in type pos
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/completions.rs | 3 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/qualified_path.rs | 30 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 22 |
3 files changed, 55 insertions, 0 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs index e07a4c403..fbd499900 100644 --- a/crates/ide_completion/src/completions.rs +++ b/crates/ide_completion/src/completions.rs | |||
@@ -204,6 +204,9 @@ impl Completions { | |||
204 | variant: hir::Variant, | 204 | variant: hir::Variant, |
205 | local_name: Option<hir::Name>, | 205 | local_name: Option<hir::Name>, |
206 | ) { | 206 | ) { |
207 | if ctx.expects_type() { | ||
208 | return; | ||
209 | } | ||
207 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); | 210 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); |
208 | self.add(item); | 211 | self.add(item); |
209 | } | 212 | } |
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index d58745fb4..a5cba5938 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs | |||
@@ -199,6 +199,36 @@ mod tests { | |||
199 | } | 199 | } |
200 | 200 | ||
201 | #[test] | 201 | #[test] |
202 | fn dont_complete_values_in_type_pos() { | ||
203 | check( | ||
204 | r#" | ||
205 | const FOO: () = (); | ||
206 | static BAR: () = (); | ||
207 | struct Baz; | ||
208 | fn foo() { | ||
209 | let _: self::$0; | ||
210 | } | ||
211 | "#, | ||
212 | expect![[r#" | ||
213 | st Baz | ||
214 | "#]], | ||
215 | ); | ||
216 | } | ||
217 | |||
218 | #[test] | ||
219 | fn dont_complete_enum_variants_in_type_pos() { | ||
220 | check( | ||
221 | r#" | ||
222 | enum Foo { Bar } | ||
223 | fn foo() { | ||
224 | let _: Foo::$0; | ||
225 | } | ||
226 | "#, | ||
227 | expect![[r#""#]], | ||
228 | ); | ||
229 | } | ||
230 | |||
231 | #[test] | ||
202 | fn dont_complete_current_use_in_braces_with_glob() { | 232 | fn dont_complete_current_use_in_braces_with_glob() { |
203 | check( | 233 | check( |
204 | r#" | 234 | r#" |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index f370dbdf0..2105bb428 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -69,6 +69,28 @@ mod tests { | |||
69 | } | 69 | } |
70 | 70 | ||
71 | #[test] | 71 | #[test] |
72 | fn dont_complete_values_in_type_pos() { | ||
73 | check( | ||
74 | r#" | ||
75 | const FOO: () = (); | ||
76 | static BAR: () = (); | ||
77 | enum Foo { | ||
78 | Bar | ||
79 | } | ||
80 | struct Baz; | ||
81 | fn foo() { | ||
82 | let local = (); | ||
83 | let _: $0; | ||
84 | } | ||
85 | "#, | ||
86 | expect![[r#" | ||
87 | en Foo | ||
88 | st Baz | ||
89 | "#]], | ||
90 | ); | ||
91 | } | ||
92 | |||
93 | #[test] | ||
72 | fn only_completes_modules_in_import() { | 94 | fn only_completes_modules_in_import() { |
73 | cov_mark::check!(only_completes_modules_in_import); | 95 | cov_mark::check!(only_completes_modules_in_import); |
74 | check( | 96 | check( |