From d4f4ae0dd88f0baf0065d612f41fea3d54af79fd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 18:46:39 +0300 Subject: Move const&static date to hir_def --- crates/ra_hir_def/src/data.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/data.rs') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index ba47629db..91bac7415 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -11,8 +11,8 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; use crate::{ db::DefDatabase2, type_ref::{Mutability, TypeRef}, - AssocItemId, AstItemDef, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, ImplId, - Intern, Lookup, TraitId, TypeAliasId, TypeAliasLoc, + AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, + ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -190,3 +190,28 @@ impl ImplData { Arc::new(res) } } + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ConstData { + pub name: Option, + pub type_ref: TypeRef, +} + +impl ConstData { + pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc { + let node = konst.lookup(db).source(db).value; + const_data_for(&node) + } + + pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc { + let node = konst.source(db).value; + const_data_for(&node) + } +} + +fn const_data_for(node: &N) -> Arc { + let name = node.name().map(|n| n.as_name()); + let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); + let sig = ConstData { name, type_ref }; + Arc::new(sig) +} -- cgit v1.2.3