aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/qualified_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/qualified_path.rs')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index 7a0e1ead3..de58ce1cd 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -1,6 +1,6 @@
1//! Completion of paths, i.e. `some::prefix::$0`. 1//! Completion of paths, i.e. `some::prefix::$0`.
2 2
3use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; 3use hir::HasVisibility;
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
5use syntax::AstNode; 5use syntax::AstNode;
6 6
@@ -21,14 +21,14 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
21 }; 21 };
22 let context_module = ctx.scope.module(); 22 let context_module = ctx.scope.module();
23 if ctx.expects_assoc_item() { 23 if ctx.expects_assoc_item() {
24 if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { 24 if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
25 let module_scope = module.scope(ctx.db, context_module); 25 let module_scope = module.scope(ctx.db, context_module);
26 for (name, def) in module_scope { 26 for (name, def) in module_scope {
27 if let ScopeDef::MacroDef(macro_def) = def { 27 if let hir::ScopeDef::MacroDef(macro_def) = def {
28 acc.add_macro(ctx, Some(name.to_string()), macro_def); 28 acc.add_macro(ctx, Some(name.clone()), macro_def);
29 } 29 }
30 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { 30 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
31 acc.add_resolution(ctx, name.to_string(), &def); 31 acc.add_resolution(ctx, name, &def);
32 } 32 }
33 } 33 }
34 } 34 }
@@ -42,11 +42,11 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
42 }); 42 });
43 43
44 match resolution { 44 match resolution {
45 PathResolution::Def(hir::ModuleDef::Module(module)) => { 45 hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
46 let module_scope = module.scope(ctx.db, context_module); 46 let module_scope = module.scope(ctx.db, context_module);
47 for (name, def) in module_scope { 47 for (name, def) in module_scope {
48 if ctx.use_item_syntax.is_some() { 48 if ctx.use_item_syntax.is_some() {
49 if let ScopeDef::Unknown = def { 49 if let hir::ScopeDef::Unknown = def {
50 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { 50 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
51 if name_ref.syntax().text() == name.to_string().as_str() { 51 if name_ref.syntax().text() == name.to_string().as_str() {
52 // for `use self::foo$0`, don't suggest `foo` as a completion 52 // for `use self::foo$0`, don't suggest `foo` as a completion
@@ -57,20 +57,20 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
57 } 57 }
58 } 58 }
59 59
60 acc.add_resolution(ctx, name.to_string(), &def); 60 acc.add_resolution(ctx, name, &def);
61 } 61 }
62 } 62 }
63 PathResolution::Def(def @ hir::ModuleDef::Adt(_)) 63 hir::PathResolution::Def(def @ hir::ModuleDef::Adt(_))
64 | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) 64 | hir::PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_))
65 | PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { 65 | hir::PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => {
66 if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { 66 if let hir::ModuleDef::Adt(hir::Adt::Enum(e)) = def {
67 add_enum_variants(ctx, acc, e); 67 add_enum_variants(ctx, acc, e);
68 } 68 }
69 let ty = match def { 69 let ty = match def {
70 hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), 70 hir::ModuleDef::Adt(adt) => adt.ty(ctx.db),
71 hir::ModuleDef::TypeAlias(a) => { 71 hir::ModuleDef::TypeAlias(a) => {
72 let ty = a.ty(ctx.db); 72 let ty = a.ty(ctx.db);
73 if let Some(Adt::Enum(e)) = ty.as_adt() { 73 if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
74 cov_mark::hit!(completes_variant_through_alias); 74 cov_mark::hit!(completes_variant_through_alias);
75 add_enum_variants(ctx, acc, e); 75 add_enum_variants(ctx, acc, e);
76 } 76 }
@@ -117,7 +117,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
117 }); 117 });
118 } 118 }
119 } 119 }
120 PathResolution::Def(hir::ModuleDef::Trait(t)) => { 120 hir::PathResolution::Def(hir::ModuleDef::Trait(t)) => {
121 // Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`. 121 // Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
122 for item in t.items(ctx.db) { 122 for item in t.items(ctx.db) {
123 if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) { 123 if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) {
@@ -130,15 +130,15 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
130 } 130 }
131 } 131 }
132 } 132 }
133 PathResolution::TypeParam(_) | PathResolution::SelfType(_) => { 133 hir::PathResolution::TypeParam(_) | hir::PathResolution::SelfType(_) => {
134 if let Some(krate) = ctx.krate { 134 if let Some(krate) = ctx.krate {
135 let ty = match resolution { 135 let ty = match resolution {
136 PathResolution::TypeParam(param) => param.ty(ctx.db), 136 hir::PathResolution::TypeParam(param) => param.ty(ctx.db),
137 PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db), 137 hir::PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db),
138 _ => return, 138 _ => return,
139 }; 139 };
140 140
141 if let Some(Adt::Enum(e)) = ty.as_adt() { 141 if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
142 add_enum_variants(ctx, acc, e); 142 add_enum_variants(ctx, acc, e);
143 } 143 }
144 144