From 1a26af15ef190bf605d3a04005aea02664815fb0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 8 Jun 2021 20:27:25 +0200 Subject: Add tests checking no value completion in type pos --- crates/ide_completion/src/completions.rs | 3 +++ .../src/completions/qualified_path.rs | 30 ++++++++++++++++++++++ .../src/completions/unqualified_path.rs | 22 ++++++++++++++++ 3 files changed, 55 insertions(+) (limited to 'crates') 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 { variant: hir::Variant, local_name: Option, ) { + if ctx.expects_type() { + return; + } let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); self.add(item); } 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 @@ -198,6 +198,36 @@ mod tests { check(r#"use self::foo$0;"#, expect![[""]]); } + #[test] + fn dont_complete_values_in_type_pos() { + check( + r#" +const FOO: () = (); +static BAR: () = (); +struct Baz; +fn foo() { + let _: self::$0; +} +"#, + expect![[r#" + st Baz + "#]], + ); + } + + #[test] + fn dont_complete_enum_variants_in_type_pos() { + check( + r#" +enum Foo { Bar } +fn foo() { + let _: Foo::$0; +} +"#, + expect![[r#""#]], + ); + } + #[test] fn dont_complete_current_use_in_braces_with_glob() { check( 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 @@ -68,6 +68,28 @@ mod tests { expect.assert_eq(&actual) } + #[test] + fn dont_complete_values_in_type_pos() { + check( + r#" +const FOO: () = (); +static BAR: () = (); +enum Foo { + Bar +} +struct Baz; +fn foo() { + let local = (); + let _: $0; +} +"#, + expect![[r#" + en Foo + st Baz + "#]], + ); + } + #[test] fn only_completes_modules_in_import() { cov_mark::check!(only_completes_modules_in_import); -- cgit v1.2.3