aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_hir_def/src/type_alias.rs27
3 files changed, 33 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 844f8bbe8..5bbdaa4b2 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -15,7 +15,8 @@ use crate::{
15 CrateDefMap, 15 CrateDefMap,
16 }, 16 },
17 traits::TraitData, 17 traits::TraitData,
18 DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, 18 type_alias::TypeAliasData,
19 DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, TypeAliasId,
19}; 20};
20 21
21#[salsa::query_group(InternDatabaseStorage)] 22#[salsa::query_group(InternDatabaseStorage)]
@@ -64,6 +65,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
64 #[salsa::invoke(TraitData::trait_data_query)] 65 #[salsa::invoke(TraitData::trait_data_query)]
65 fn trait_data(&self, e: TraitId) -> Arc<TraitData>; 66 fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
66 67
68 #[salsa::invoke(TypeAliasData::type_alias_data_query)]
69 fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
70
67 #[salsa::invoke(Body::body_with_source_map_query)] 71 #[salsa::invoke(Body::body_with_source_map_query)]
68 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); 72 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
69 73
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index d579f5c7e..268144462 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -20,6 +20,7 @@ pub mod body;
20pub mod generics; 20pub mod generics;
21pub mod traits; 21pub mod traits;
22pub mod resolver; 22pub mod resolver;
23pub mod type_alias;
23 24
24#[cfg(test)] 25#[cfg(test)]
25mod test_db; 26mod test_db;
diff --git a/crates/ra_hir_def/src/type_alias.rs b/crates/ra_hir_def/src/type_alias.rs
new file mode 100644
index 000000000..c0b49aa7c
--- /dev/null
+++ b/crates/ra_hir_def/src/type_alias.rs
@@ -0,0 +1,27 @@
1//! HIR for type aliases (i.e. the `type` keyword).
2
3use std::sync::Arc;
4
5use hir_expand::name::{AsName, Name};
6
7use ra_syntax::ast::NameOwner;
8
9use crate::{db::DefDatabase2, type_ref::TypeRef, HasSource, Lookup, TypeAliasId};
10
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct TypeAliasData {
13 pub name: Name,
14 pub type_ref: Option<TypeRef>,
15}
16
17impl TypeAliasData {
18 pub(crate) fn type_alias_data_query(
19 db: &impl DefDatabase2,
20 typ: TypeAliasId,
21 ) -> Arc<TypeAliasData> {
22 let node = typ.lookup(db).source(db).value;
23 let name = node.name().map_or_else(Name::missing, |n| n.as_name());
24 let type_ref = node.type_ref().map(TypeRef::from_ast);
25 Arc::new(TypeAliasData { name, type_ref })
26 }
27}