add completions to show only traits with qualified path prefix
This commit is contained in:
parent
0209c28136
commit
9897662bf7
@ -31,6 +31,11 @@ pub(crate) fn complete_type_path(
|
|||||||
ScopeDef::ImplSelfType(_) => location.complete_self_type(),
|
ScopeDef::ImplSelfType(_) => location.complete_self_type(),
|
||||||
// Don't suggest attribute macros and derives.
|
// Don't suggest attribute macros and derives.
|
||||||
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
|
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
|
||||||
|
ScopeDef::ModuleDef(Trait(_) | Module(_))
|
||||||
|
if matches!(location, TypeLocation::ImplTrait) =>
|
||||||
|
{
|
||||||
|
true
|
||||||
|
}
|
||||||
// Type things are fine
|
// Type things are fine
|
||||||
ScopeDef::ModuleDef(
|
ScopeDef::ModuleDef(
|
||||||
BuiltinType(_) | Adt(_) | Module(_) | Trait(_) | TraitAlias(_) | TypeAlias(_),
|
BuiltinType(_) | Adt(_) | Module(_) | Trait(_) | TraitAlias(_) | TypeAlias(_),
|
||||||
@ -187,8 +192,13 @@ pub(crate) fn complete_type_path(
|
|||||||
TypeLocation::ImplTrait => {
|
TypeLocation::ImplTrait => {
|
||||||
acc.add_nameref_keywords_with_colon(ctx);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
ctx.process_all_names(&mut |name, def, doc_aliases| {
|
ctx.process_all_names(&mut |name, def, doc_aliases| {
|
||||||
let is_trait = matches!(def, ScopeDef::ModuleDef(hir::ModuleDef::Trait(_)));
|
let is_trait_or_module = matches!(
|
||||||
if is_trait {
|
def,
|
||||||
|
ScopeDef::ModuleDef(
|
||||||
|
hir::ModuleDef::Module(_) | hir::ModuleDef::Trait(_)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if is_trait_or_module {
|
||||||
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases);
|
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -202,6 +202,7 @@ impl TypeLocation {
|
|||||||
}
|
}
|
||||||
TypeLocation::AssocConstEq => false,
|
TypeLocation::AssocConstEq => false,
|
||||||
TypeLocation::AssocTypeEq => true,
|
TypeLocation::AssocTypeEq => true,
|
||||||
|
TypeLocation::ImplTrait => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -998,8 +998,10 @@ trait Foo {}
|
|||||||
|
|
||||||
struct Bar;
|
struct Bar;
|
||||||
|
|
||||||
impl $0 for Bar { }"#,
|
impl $0 for Bar { }
|
||||||
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
md module
|
||||||
tt Foo
|
tt Foo
|
||||||
tt Trait
|
tt Trait
|
||||||
kw crate::
|
kw crate::
|
||||||
@ -1007,3 +1009,23 @@ impl $0 for Bar { }"#,
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn complete_traits_with_path_on_impl_trait_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod outer {
|
||||||
|
pub trait Foo {}
|
||||||
|
pub struct Bar;
|
||||||
|
pub mod inner {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl outer::$0 for Bar { }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md inner
|
||||||
|
tt Foo
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user