diff options
Diffstat (limited to 'crates/ra_hir_def/src/data.rs')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 29 |
1 files changed, 27 insertions, 2 deletions
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}; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase2, | 12 | db::DefDatabase2, |
13 | type_ref::{Mutability, TypeRef}, | 13 | type_ref::{Mutability, TypeRef}, |
14 | AssocItemId, AstItemDef, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, ImplId, | 14 | AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, |
15 | Intern, Lookup, TraitId, TypeAliasId, TypeAliasLoc, | 15 | ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #[derive(Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -190,3 +190,28 @@ impl ImplData { | |||
190 | Arc::new(res) | 190 | Arc::new(res) |
191 | } | 191 | } |
192 | } | 192 | } |
193 | |||
194 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
195 | pub struct ConstData { | ||
196 | pub name: Option<Name>, | ||
197 | pub type_ref: TypeRef, | ||
198 | } | ||
199 | |||
200 | impl ConstData { | ||
201 | pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc<ConstData> { | ||
202 | let node = konst.lookup(db).source(db).value; | ||
203 | const_data_for(&node) | ||
204 | } | ||
205 | |||
206 | pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc<ConstData> { | ||
207 | let node = konst.source(db).value; | ||
208 | const_data_for(&node) | ||
209 | } | ||
210 | } | ||
211 | |||
212 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { | ||
213 | let name = node.name().map(|n| n.as_name()); | ||
214 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | ||
215 | let sig = ConstData { name, type_ref }; | ||
216 | Arc::new(sig) | ||
217 | } | ||