Unnamed repository; edit this file 'description' to name the repository.
fix: Not suggest name in nested type in variant
Example --- ```rust struct Other; struct Vec<T>(T); enum Foo { Vec(Vec<$0>) } ``` **Before this PR** ```text st Vec<…> Vec<{unknown}> [name] en Foo Foo [] st Other Other [] sp Self Foo [] ``` **After this PR** ```text en Foo Foo [] st Other Other [] sp Self Foo [] st Vec<…> Vec<{unknown}> [] ```
A4-Tacks 7 weeks ago
parent 63b3eff · commit 4136f7b
-rw-r--r--crates/ide-completion/src/context/analysis.rs5
-rw-r--r--crates/ide-completion/src/render.rs16
2 files changed, 21 insertions, 0 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index 762e60d676..294e70dd56 100644
--- a/crates/ide-completion/src/context/analysis.rs
+++ b/crates/ide-completion/src/context/analysis.rs
@@ -828,10 +828,15 @@ fn expected_type_and_name<'db>(
.unwrap_or((None, None))
},
ast::Variant(it) => {
+ let is_simple_field = |field: ast::TupleField| {
+ let Some(ty) = field.ty() else { return true };
+ matches!(ty, ast::Type::PathType(_)) && ty.generic_arg_list().is_none()
+ };
let is_simple_variant = matches!(
it.field_list(),
Some(ast::FieldList::TupleFieldList(list))
if list.syntax().children_with_tokens().all(|it| it.kind() != T![,])
+ && list.fields().next().is_none_or(is_simple_field)
);
(None, it.name().filter(|_| is_simple_variant).map(NameOrNameRef::Name))
},
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 89e15a0cd1..4751ee36ec 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -3077,6 +3077,22 @@ enum Foo {
st String String []
"#]],
);
+
+ check_relevance(
+ r#"
+struct Other;
+struct Vec<T>(T);
+enum Foo {
+ Vec(Vec<$0>)
+}
+ "#,
+ expect![[r#"
+ en Foo Foo []
+ st Other Other []
+ sp Self Foo []
+ st Vec<…> Vec<{unknown}> []
+ "#]],
+ );
}
#[test]