Skip to content

fix: Don't show assoc. type binding completions when invalid #12199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions crates/ide-completion/src/completions/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
if let Some(ImmediateLocation::GenericArgList(arg_list)) = &ctx.completion_location {
if let Some(path_seg) = arg_list.syntax().parent().and_then(ast::PathSegment::cast)
{
if let Some(hir::PathResolution::Def(hir::ModuleDef::Trait(trait_))) =
ctx.sema.resolve_path(&path_seg.parent_path())
{
trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
if let hir::AssocItem::TypeAlias(alias) = it {
cov_mark::hit!(complete_assoc_type_in_generics_list);
acc.add_type_alias_with_eq(ctx, alias)
}
});
if path_seg.syntax().ancestors().find_map(ast::TypeBound::cast).is_some() {
if let Some(hir::PathResolution::Def(hir::ModuleDef::Trait(trait_))) =
ctx.sema.resolve_path(&path_seg.parent_path())
{
trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
if let hir::AssocItem::TypeAlias(alias) = it {
cov_mark::hit!(complete_assoc_type_in_generics_list);
acc.add_type_alias_with_eq(ctx, alias)
}
});
}
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions crates/ide-completion/src/tests/type_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,38 @@ fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
);
}

#[test]
fn no_assoc_completion_outside_type_bounds() {
check(
r#"
struct S;
trait Tr<T> {
type Ty;
}

impl Tr<$0
"#,
expect![[r#"
ct CONST
en Enum
ma makro!(…) macro_rules! makro
md module
sp Self
st Record
st S
st Tuple
st Unit
tt Tr
tt Trait
un Union
bt u32
kw crate::
kw self::
kw super::
"#]],
);
}

#[test]
fn enum_qualified() {
check(
Expand Down