Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9897662

Browse files
committed
add completions to show only traits with qualified path prefix
1 parent 0209c28 commit 9897662

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub(crate) fn complete_type_path(
3131
ScopeDef::ImplSelfType(_) => location.complete_self_type(),
3232
// Don't suggest attribute macros and derives.
3333
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
34+
ScopeDef::ModuleDef(Trait(_) | Module(_))
35+
if matches!(location, TypeLocation::ImplTrait) =>
36+
{
37+
true
38+
}
3439
// Type things are fine
3540
ScopeDef::ModuleDef(
3641
BuiltinType(_) | Adt(_) | Module(_) | Trait(_) | TraitAlias(_) | TypeAlias(_),
@@ -187,8 +192,13 @@ pub(crate) fn complete_type_path(
187192
TypeLocation::ImplTrait => {
188193
acc.add_nameref_keywords_with_colon(ctx);
189194
ctx.process_all_names(&mut |name, def, doc_aliases| {
190-
let is_trait = matches!(def, ScopeDef::ModuleDef(hir::ModuleDef::Trait(_)));
191-
if is_trait {
195+
let is_trait_or_module = matches!(
196+
def,
197+
ScopeDef::ModuleDef(
198+
hir::ModuleDef::Module(_) | hir::ModuleDef::Trait(_)
199+
)
200+
);
201+
if is_trait_or_module {
192202
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases);
193203
}
194204
});

crates/ide-completion/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ impl TypeLocation {
202202
}
203203
TypeLocation::AssocConstEq => false,
204204
TypeLocation::AssocTypeEq => true,
205+
TypeLocation::ImplTrait => false,
205206
_ => true,
206207
}
207208
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,34 @@ trait Foo {}
998998
999999
struct Bar;
10001000
1001-
impl $0 for Bar { }"#,
1001+
impl $0 for Bar { }
1002+
"#,
10021003
expect![[r#"
1004+
md module
10031005
tt Foo
10041006
tt Trait
10051007
kw crate::
10061008
kw self::
10071009
"#]],
10081010
);
10091011
}
1012+
1013+
#[test]
1014+
fn complete_traits_with_path_on_impl_trait_block() {
1015+
check(
1016+
r#"
1017+
mod outer {
1018+
pub trait Foo {}
1019+
pub struct Bar;
1020+
pub mod inner {
1021+
}
1022+
}
1023+
1024+
impl outer::$0 for Bar { }
1025+
"#,
1026+
expect![[r#"
1027+
md inner
1028+
tt Foo
1029+
"#]],
1030+
);
1031+
}

0 commit comments

Comments
 (0)