diff options
Diffstat (limited to 'crates/ide_completion/src/completions')
5 files changed, 29 insertions, 30 deletions
diff --git a/crates/ide_completion/src/completions/lifetime.rs b/crates/ide_completion/src/completions/lifetime.rs index 5f6285b84..8ccccb646 100644 --- a/crates/ide_completion/src/completions/lifetime.rs +++ b/crates/ide_completion/src/completions/lifetime.rs | |||
@@ -16,15 +16,14 @@ pub(crate) fn complete_lifetime(acc: &mut Completions, ctx: &CompletionContext) | |||
16 | (Some(lt), Some(lp)) if lp == lt.clone() => return, | 16 | (Some(lt), Some(lp)) if lp == lt.clone() => return, |
17 | (Some(_), Some(lp)) => { | 17 | (Some(_), Some(lp)) => { |
18 | lp_string = lp.to_string(); | 18 | lp_string = lp.to_string(); |
19 | Some(&lp_string) | 19 | Some(&*lp_string) |
20 | } | 20 | } |
21 | _ => None, | 21 | _ => None, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | ctx.scope.process_all_names(&mut |name, res| { | 24 | ctx.scope.process_all_names(&mut |name, res| { |
25 | if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { | 25 | if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { |
26 | let name = name.to_string(); | 26 | if param_lifetime != Some(&*name.to_string()) { |
27 | if param_lifetime != Some(&name) { | ||
28 | acc.add_resolution(ctx, name, &res); | 27 | acc.add_resolution(ctx, name, &res); |
29 | } | 28 | } |
30 | } | 29 | } |
@@ -41,7 +40,7 @@ pub(crate) fn complete_label(acc: &mut Completions, ctx: &CompletionContext) { | |||
41 | } | 40 | } |
42 | ctx.scope.process_all_names(&mut |name, res| { | 41 | ctx.scope.process_all_names(&mut |name, res| { |
43 | if let ScopeDef::Label(_) = res { | 42 | if let ScopeDef::Label(_) = res { |
44 | acc.add_resolution(ctx, name.to_string(), &res); | 43 | acc.add_resolution(ctx, name, &res); |
45 | } | 44 | } |
46 | }); | 45 | }); |
47 | } | 46 | } |
diff --git a/crates/ide_completion/src/completions/macro_in_item_position.rs b/crates/ide_completion/src/completions/macro_in_item_position.rs index ec57aee30..202e71215 100644 --- a/crates/ide_completion/src/completions/macro_in_item_position.rs +++ b/crates/ide_completion/src/completions/macro_in_item_position.rs | |||
@@ -11,11 +11,11 @@ pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl | |||
11 | 11 | ||
12 | ctx.scope.process_all_names(&mut |name, res| { | 12 | ctx.scope.process_all_names(&mut |name, res| { |
13 | if let hir::ScopeDef::MacroDef(mac) = res { | 13 | if let hir::ScopeDef::MacroDef(mac) = res { |
14 | acc.add_macro(ctx, Some(name.to_string()), mac); | 14 | acc.add_macro(ctx, Some(name.clone()), mac); |
15 | } | 15 | } |
16 | // FIXME: This should be done in qualified_path/unqualified_path instead? | 16 | // FIXME: This should be done in qualified_path/unqualified_path instead? |
17 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { | 17 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { |
18 | acc.add_resolution(ctx, name.to_string(), &res); | 18 | acc.add_resolution(ctx, name, &res); |
19 | } | 19 | } |
20 | }) | 20 | }) |
21 | } | 21 | } |
diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index b84e9a967..8a728c67e 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs | |||
@@ -51,7 +51,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
51 | _ => false, | 51 | _ => false, |
52 | }; | 52 | }; |
53 | if add_resolution { | 53 | if add_resolution { |
54 | acc.add_resolution(ctx, name.to_string(), &res); | 54 | acc.add_resolution(ctx, name, &res); |
55 | } | 55 | } |
56 | }); | 56 | }); |
57 | } | 57 | } |
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 | ||
3 | use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; | 3 | use hir::HasVisibility; |
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
5 | use syntax::AstNode; | 5 | use 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 | ||
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index ede07f605..9db8516d0 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -14,10 +14,10 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
14 | if ctx.expects_assoc_item() { | 14 | if ctx.expects_assoc_item() { |
15 | ctx.scope.process_all_names(&mut |name, def| { | 15 | ctx.scope.process_all_names(&mut |name, def| { |
16 | if let ScopeDef::MacroDef(macro_def) = def { | 16 | if let ScopeDef::MacroDef(macro_def) = def { |
17 | acc.add_macro(ctx, Some(name.to_string()), macro_def); | 17 | acc.add_macro(ctx, Some(name.clone()), macro_def); |
18 | } | 18 | } |
19 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { | 19 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { |
20 | acc.add_resolution(ctx, name.to_string(), &def); | 20 | acc.add_resolution(ctx, name, &def); |
21 | } | 21 | } |
22 | }); | 22 | }); |
23 | return; | 23 | return; |
@@ -27,7 +27,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
27 | cov_mark::hit!(only_completes_modules_in_import); | 27 | cov_mark::hit!(only_completes_modules_in_import); |
28 | ctx.scope.process_all_names(&mut |name, res| { | 28 | ctx.scope.process_all_names(&mut |name, res| { |
29 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { | 29 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { |
30 | acc.add_resolution(ctx, name.to_string(), &res); | 30 | acc.add_resolution(ctx, name, &res); |
31 | } | 31 | } |
32 | }); | 32 | }); |
33 | return; | 33 | return; |
@@ -45,7 +45,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
45 | cov_mark::hit!(skip_lifetime_completion); | 45 | cov_mark::hit!(skip_lifetime_completion); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | acc.add_resolution(ctx, name.to_string(), &res); | 48 | acc.add_resolution(ctx, name, &res); |
49 | }); | 49 | }); |
50 | } | 50 | } |
51 | 51 | ||