diff options
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 24 | ||||
-rw-r--r-- | crates/hir/src/code_model.rs | 2 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/resolver.rs | 25 |
4 files changed, 41 insertions, 12 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index ac5596ca4..809e1645a 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -29,6 +29,10 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
29 | } | 29 | } |
30 | 30 | ||
31 | ctx.scope.process_all_names(&mut |name, res| { | 31 | ctx.scope.process_all_names(&mut |name, res| { |
32 | if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { | ||
33 | mark::hit!(skip_lifetime_completion); | ||
34 | return; | ||
35 | } | ||
32 | if ctx.use_item_syntax.is_some() { | 36 | if ctx.use_item_syntax.is_some() { |
33 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { | 37 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { |
34 | if name_ref.syntax().text() == name.to_string().as_str() { | 38 | if name_ref.syntax().text() == name.to_string().as_str() { |
@@ -37,7 +41,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
37 | } | 41 | } |
38 | } | 42 | } |
39 | } | 43 | } |
40 | acc.add_resolution(ctx, name.to_string(), &res) | 44 | acc.add_resolution(ctx, name.to_string(), &res); |
41 | }); | 45 | }); |
42 | } | 46 | } |
43 | 47 | ||
@@ -234,6 +238,24 @@ fn main() { | |||
234 | fn quux() fn quux<T>() | 238 | fn quux() fn quux<T>() |
235 | "#]], | 239 | "#]], |
236 | ); | 240 | ); |
241 | check( | ||
242 | r#"fn quux<const C: usize>() { $0 }"#, | ||
243 | expect![[r#" | ||
244 | tp C | ||
245 | fn quux() fn quux<const C: usize>() | ||
246 | "#]], | ||
247 | ); | ||
248 | } | ||
249 | |||
250 | #[test] | ||
251 | fn does_not_complete_lifetimes() { | ||
252 | mark::check!(skip_lifetime_completion); | ||
253 | check( | ||
254 | r#"fn quux<'a>() { $0 }"#, | ||
255 | expect![[r#" | ||
256 | fn quux() fn quux<'a>() | ||
257 | "#]], | ||
258 | ); | ||
237 | } | 259 | } |
238 | 260 | ||
239 | #[test] | 261 | #[test] |
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 5a4c27906..a4141e111 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -2046,7 +2046,7 @@ impl Callable { | |||
2046 | pub enum ScopeDef { | 2046 | pub enum ScopeDef { |
2047 | ModuleDef(ModuleDef), | 2047 | ModuleDef(ModuleDef), |
2048 | MacroDef(MacroDef), | 2048 | MacroDef(MacroDef), |
2049 | GenericParam(TypeParam), | 2049 | GenericParam(GenericParam), |
2050 | ImplSelfType(Impl), | 2050 | ImplSelfType(Impl), |
2051 | AdtSelfType(Adt), | 2051 | AdtSelfType(Adt), |
2052 | Local(Local), | 2052 | Local(Local), |
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index ab213e04c..0a30b4f5b 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -814,7 +814,7 @@ impl<'a> SemanticsScope<'a> { | |||
814 | } | 814 | } |
815 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), | 815 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), |
816 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), | 816 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), |
817 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(TypeParam { id }), | 817 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(id.into()), |
818 | resolver::ScopeDef::Local(pat_id) => { | 818 | resolver::ScopeDef::Local(pat_id) => { |
819 | let parent = resolver.body_owner().unwrap().into(); | 819 | let parent = resolver.body_owner().unwrap().into(); |
820 | ScopeDef::Local(Local { parent, pat_id }) | 820 | ScopeDef::Local(Local { parent, pat_id }) |
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index e7e92c72d..a505bf2be 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs | |||
@@ -21,8 +21,9 @@ use crate::{ | |||
21 | per_ns::PerNs, | 21 | per_ns::PerNs, |
22 | visibility::{RawVisibility, Visibility}, | 22 | visibility::{RawVisibility, Visibility}, |
23 | AdtId, AssocContainerId, ConstId, ConstParamId, ContainerId, DefWithBodyId, EnumId, | 23 | AdtId, AssocContainerId, ConstId, ConstParamId, ContainerId, DefWithBodyId, EnumId, |
24 | EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, | 24 | EnumVariantId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, |
25 | ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, | 25 | LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, |
26 | TypeParamId, VariantId, | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | #[derive(Debug, Clone, Default)] | 29 | #[derive(Debug, Clone, Default)] |
@@ -484,7 +485,7 @@ pub enum ScopeDef { | |||
484 | PerNs(PerNs), | 485 | PerNs(PerNs), |
485 | ImplSelfType(ImplId), | 486 | ImplSelfType(ImplId), |
486 | AdtSelfType(AdtId), | 487 | AdtSelfType(AdtId), |
487 | GenericParam(TypeParamId), | 488 | GenericParam(GenericParamId), |
488 | Local(PatId), | 489 | Local(PatId), |
489 | } | 490 | } |
490 | 491 | ||
@@ -527,15 +528,21 @@ impl Scope { | |||
527 | Scope::LocalItemsScope(body) => body.item_scope.entries().for_each(|(name, def)| { | 528 | Scope::LocalItemsScope(body) => body.item_scope.entries().for_each(|(name, def)| { |
528 | f(name.clone(), ScopeDef::PerNs(def)); | 529 | f(name.clone(), ScopeDef::PerNs(def)); |
529 | }), | 530 | }), |
530 | Scope::GenericParams { params, def } => { | 531 | &Scope::GenericParams { ref params, def: parent } => { |
531 | for (local_id, param) in params.types.iter() { | 532 | for (local_id, param) in params.types.iter() { |
532 | if let Some(name) = ¶m.name { | 533 | if let Some(ref name) = param.name { |
533 | f( | 534 | let id = TypeParamId { local_id, parent }; |
534 | name.clone(), | 535 | f(name.clone(), ScopeDef::GenericParam(id.into())) |
535 | ScopeDef::GenericParam(TypeParamId { local_id, parent: *def }), | ||
536 | ) | ||
537 | } | 536 | } |
538 | } | 537 | } |
538 | for (local_id, param) in params.consts.iter() { | ||
539 | let id = ConstParamId { local_id, parent }; | ||
540 | f(param.name.clone(), ScopeDef::GenericParam(id.into())) | ||
541 | } | ||
542 | for (local_id, param) in params.lifetimes.iter() { | ||
543 | let id = LifetimeParamId { local_id, parent }; | ||
544 | f(param.name.clone(), ScopeDef::GenericParam(id.into())) | ||
545 | } | ||
539 | } | 546 | } |
540 | Scope::ImplDefScope(i) => { | 547 | Scope::ImplDefScope(i) => { |
541 | f(name![Self], ScopeDef::ImplSelfType(*i)); | 548 | f(name![Self], ScopeDef::ImplSelfType(*i)); |