diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs index e07a4c403f..fbd499900a 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 d58745fb4d..a5cba59388 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 f370dbdf0b..2105bb4287 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);