Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-completion/src/context/analysis.rs8
-rw-r--r--crates/ide-completion/src/render.rs35
2 files changed, 43 insertions, 0 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index bf899539a2..a299ad66ce 100644
--- a/crates/ide-completion/src/context/analysis.rs
+++ b/crates/ide-completion/src/context/analysis.rs
@@ -827,6 +827,14 @@ fn expected_type_and_name<'db>(
.map(|c| (Some(c.return_type()), None))
.unwrap_or((None, None))
},
+ ast::Variant(it) => {
+ let is_simple_variant = matches!(
+ it.field_list(),
+ Some(ast::FieldList::TupleFieldList(list))
+ if list.syntax().children_with_tokens().all(|it| it.kind() != T![,])
+ );
+ (None, it.name().filter(|_| is_simple_variant).map(NameOrNameRef::Name))
+ },
ast::Stmt(_) => (None, None),
ast::Item(_) => (None, None),
_ => {
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 765304d818..8d79c0fe8a 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -3045,6 +3045,41 @@ fn main() {
}
#[test]
+ fn enum_variant_name_exact_match_is_high_priority() {
+ check_relevance(
+ r#"
+struct Other;
+struct String;
+enum Foo {
+ String($0)
+}
+ "#,
+ expect![[r#"
+ st String String [name]
+ en Foo Foo []
+ st Other Other []
+ sp Self Foo []
+ "#]],
+ );
+
+ check_relevance(
+ r#"
+struct Other;
+struct String;
+enum Foo {
+ String(String, $0)
+}
+ "#,
+ expect![[r#"
+ en Foo Foo []
+ st Other Other []
+ sp Self Foo []
+ st String String []
+ "#]],
+ );
+ }
+
+ #[test]
fn postfix_inexact_match_is_low_priority() {
cov_mark::check!(postfix_inexact_match_is_low_priority);
check_relevance_for_kinds(