From bed12833cc4ce7c6b4085ba8dc47fc167c83f8ea Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 19 Jan 2021 20:01:49 +0100 Subject: Show const params in completions --- crates/hir_def/src/resolver.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'crates/hir_def/src/resolver.rs') 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::{ per_ns::PerNs, visibility::{RawVisibility, Visibility}, AdtId, AssocContainerId, ConstId, ConstParamId, ContainerId, DefWithBodyId, EnumId, - EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, - ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, + EnumVariantId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, + LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, + TypeParamId, VariantId, }; #[derive(Debug, Clone, Default)] @@ -484,7 +485,7 @@ pub enum ScopeDef { PerNs(PerNs), ImplSelfType(ImplId), AdtSelfType(AdtId), - GenericParam(TypeParamId), + GenericParam(GenericParamId), Local(PatId), } @@ -527,15 +528,21 @@ impl Scope { Scope::LocalItemsScope(body) => body.item_scope.entries().for_each(|(name, def)| { f(name.clone(), ScopeDef::PerNs(def)); }), - Scope::GenericParams { params, def } => { + &Scope::GenericParams { ref params, def: parent } => { for (local_id, param) in params.types.iter() { - if let Some(name) = ¶m.name { - f( - name.clone(), - ScopeDef::GenericParam(TypeParamId { local_id, parent: *def }), - ) + if let Some(ref name) = param.name { + let id = TypeParamId { local_id, parent }; + f(name.clone(), ScopeDef::GenericParam(id.into())) } } + for (local_id, param) in params.consts.iter() { + let id = ConstParamId { local_id, parent }; + f(param.name.clone(), ScopeDef::GenericParam(id.into())) + } + for (local_id, param) in params.lifetimes.iter() { + let id = LifetimeParamId { local_id, parent }; + f(param.name.clone(), ScopeDef::GenericParam(id.into())) + } } Scope::ImplDefScope(i) => { f(name![Self], ScopeDef::ImplSelfType(*i)); -- cgit v1.2.3