Skip to content

Commit 0209c28

Browse files
committed
add completions to show only traits in trait impl statement
1 parent cf87333 commit 0209c28

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

crates/ide-completion/src/completions/type.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ pub(crate) fn complete_type_path(
184184
}
185185
}
186186
}
187+
TypeLocation::ImplTrait => {
188+
acc.add_nameref_keywords_with_colon(ctx);
189+
ctx.process_all_names(&mut |name, def, doc_aliases| {
190+
let is_trait = matches!(def, ScopeDef::ModuleDef(hir::ModuleDef::Trait(_)));
191+
if is_trait {
192+
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases);
193+
}
194+
});
195+
return;
196+
}
187197
_ => {}
188198
};
189199

crates/ide-completion/src/tests/type_pos.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,3 +989,21 @@ fn foo<'a>() { S::<'static, F$0, _, _>; }
989989
"#]],
990990
);
991991
}
992+
993+
#[test]
994+
fn complete_traits_on_impl_trait_block() {
995+
check(
996+
r#"
997+
trait Foo {}
998+
999+
struct Bar;
1000+
1001+
impl $0 for Bar { }"#,
1002+
expect![[r#"
1003+
tt Foo
1004+
tt Trait
1005+
kw crate::
1006+
kw self::
1007+
"#]],
1008+
);
1009+
}

0 commit comments

Comments
 (0)