aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-22 15:52:25 +0000
committerGitHub <[email protected]>2019-11-22 15:52:25 +0000
commit6d42db2e51e223c9be7b6ea234521ca6f93ee95a (patch)
tree895e5bb04a4a632b4069bf66f8c7770cfa80a90d /crates/ra_hir_def/src
parentb841c53a0c93cdca3f08b1c917c9fa8a63d31604 (diff)
parentfe119fef2746bade402fb73dcba8cde49779654d (diff)
Merge #2358
2358: Hide data from public API r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/data.rs29
-rw-r--r--crates/ra_hir_def/src/db.rs12
2 files changed, 36 insertions, 5 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};
11use crate::{ 11use 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)]
195pub struct ConstData {
196 pub name: Option<Name>,
197 pub type_ref: TypeRef,
198}
199
200impl 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
212fn 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}
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 8c1784ec9..2c660ab88 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -8,14 +8,14 @@ use ra_syntax::ast;
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData}, 9 adt::{EnumData, StructData},
10 body::{scope::ExprScopes, Body, BodySourceMap}, 10 body::{scope::ExprScopes, Body, BodySourceMap},
11 data::{FunctionData, ImplData, TraitData, TypeAliasData}, 11 data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData},
12 generics::GenericParams, 12 generics::GenericParams,
13 nameres::{ 13 nameres::{
14 raw::{ImportSourceMap, RawItems}, 14 raw::{ImportSourceMap, RawItems},
15 CrateDefMap, 15 CrateDefMap,
16 }, 16 },
17 DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, 17 ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StaticId,
18 TypeAliasId, 18 StructOrUnionId, TraitId, TypeAliasId,
19}; 19};
20 20
21#[salsa::query_group(InternDatabaseStorage)] 21#[salsa::query_group(InternDatabaseStorage)]
@@ -70,6 +70,12 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
70 #[salsa::invoke(FunctionData::fn_data_query)] 70 #[salsa::invoke(FunctionData::fn_data_query)]
71 fn function_data(&self, func: FunctionId) -> Arc<FunctionData>; 71 fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
72 72
73 #[salsa::invoke(ConstData::const_data_query)]
74 fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
75
76 #[salsa::invoke(ConstData::static_data_query)]
77 fn static_data(&self, konst: StaticId) -> Arc<ConstData>;
78
73 #[salsa::invoke(Body::body_with_source_map_query)] 79 #[salsa::invoke(Body::body_with_source_map_query)]
74 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); 80 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
75 81