Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_completion/src/completions/qualified_path.rs')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs56
1 files changed, 24 insertions, 32 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index c1f23ceeca..534d27d983 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -1,7 +1,6 @@
//! Completion of paths, i.e. `some::prefix::$0`.
use hir::{ScopeDef, Trait};
-use ide_db::famous_defs::FamousDefs;
use rustc_hash::FxHashSet;
use syntax::ast;
@@ -26,7 +25,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
};
let traits_in_scope = |ctx: &CompletionContext| {
let mut traits_in_scope = ctx.scope.visible_traits();
- if let Some(drop) = FamousDefs(&ctx.sema, ctx.krate).core_ops_Drop() {
+ if let Some(drop) = ctx.famous_defs().core_ops_Drop() {
traits_in_scope.remove(&drop.into());
}
traits_in_scope
@@ -58,7 +57,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
match ctx.completion_location {
Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) => {
if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
- for (name, def) in module.scope(ctx.db, ctx.module) {
+ for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
if let Some(def) = module_or_fn_macro(ctx.db, def) {
acc.add_resolution(ctx, name, def);
}
@@ -90,7 +89,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
match resolution {
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
- let module_scope = module.scope(ctx.db, ctx.module);
+ let module_scope = module.scope(ctx.db, Some(ctx.module));
for (name, def) in module_scope {
let add_resolution = match def {
// Don't suggest attribute macros and derives.
@@ -133,12 +132,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
ty
}
hir::ModuleDef::BuiltinType(builtin) => {
- let module = match ctx.module {
- Some(it) => it,
- None => return,
- };
cov_mark::hit!(completes_primitive_assoc_const);
- builtin.ty(ctx.db, module)
+ builtin.ty(ctx.db)
}
_ => unreachable!(),
};
@@ -146,29 +141,26 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
// XXX: For parity with Rust bug #22519, this does not complete Ty::AssocType.
// (where AssocType is defined on a trait, not an inherent impl)
- let krate = ctx.krate;
- if let Some(krate) = krate {
- let traits_in_scope = traits_in_scope(ctx);
- ty.iterate_path_candidates(
- ctx.db,
- &ctx.scope,
- &traits_in_scope,
- ctx.module,
- None,
- |item| {
- add_assoc_item(acc, ctx, item);
- None::<()>
- },
- );
-
- // Iterate assoc types separately
- ty.iterate_assoc_items(ctx.db, krate, |item| {
- if let hir::AssocItem::TypeAlias(ty) = item {
- acc.add_type_alias(ctx, ty)
- }
+ let traits_in_scope = traits_in_scope(ctx);
+ ty.iterate_path_candidates(
+ ctx.db,
+ &ctx.scope,
+ &traits_in_scope,
+ Some(ctx.module),
+ None,
+ |item| {
+ add_assoc_item(acc, ctx, item);
None::<()>
- });
- }
+ },
+ );
+
+ // Iterate assoc types separately
+ ty.iterate_assoc_items(ctx.db, ctx.krate, |item| {
+ if let hir::AssocItem::TypeAlias(ty) = item {
+ acc.add_type_alias(ctx, ty)
+ }
+ None::<()>
+ });
}
hir::PathResolution::Def(hir::ModuleDef::Trait(t)) => {
// Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
@@ -192,7 +184,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
ctx.db,
&ctx.scope,
&traits_in_scope,
- ctx.module,
+ Some(ctx.module),
None,
|item| {
// We might iterate candidates of a trait multiple times here, so deduplicate