diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 3 |
3 files changed, 26 insertions, 29 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 4b35c01b3..935f39959 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -1,11 +1,9 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::Cancelable; | ||
4 | use ra_syntax::ast::{self, NameOwner, StructFlavor}; | 3 | use ra_syntax::ast::{self, NameOwner, StructFlavor}; |
5 | 4 | ||
6 | use crate::{ | 5 | use crate::{ |
7 | DefId, Name, AsName, Struct, | 6 | DefId, Name, AsName, Struct, Enum, |
8 | db::HirDatabase, | ||
9 | type_ref::TypeRef, | 7 | type_ref::TypeRef, |
10 | }; | 8 | }; |
11 | 9 | ||
@@ -13,10 +11,6 @@ impl Struct { | |||
13 | pub(crate) fn new(def_id: DefId) -> Self { | 11 | pub(crate) fn new(def_id: DefId) -> Self { |
14 | Struct { def_id } | 12 | Struct { def_id } |
15 | } | 13 | } |
16 | |||
17 | pub(crate) fn struct_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<StructData>> { | ||
18 | Ok(db.struct_data(self.def_id)?) | ||
19 | } | ||
20 | } | 14 | } |
21 | 15 | ||
22 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -42,32 +36,16 @@ impl StructData { | |||
42 | } | 36 | } |
43 | } | 37 | } |
44 | 38 | ||
45 | pub struct Enum { | ||
46 | def_id: DefId, | ||
47 | } | ||
48 | |||
49 | impl Enum { | 39 | impl Enum { |
50 | pub(crate) fn new(def_id: DefId) -> Self { | 40 | pub(crate) fn new(def_id: DefId) -> Self { |
51 | Enum { def_id } | 41 | Enum { def_id } |
52 | } | 42 | } |
53 | |||
54 | pub fn def_id(&self) -> DefId { | ||
55 | self.def_id | ||
56 | } | ||
57 | |||
58 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | ||
59 | Ok(db.enum_data(self.def_id)?.name.clone()) | ||
60 | } | ||
61 | |||
62 | pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> { | ||
63 | Ok(db.enum_data(self.def_id)?.variants.clone()) | ||
64 | } | ||
65 | } | 43 | } |
66 | 44 | ||
67 | #[derive(Debug, Clone, PartialEq, Eq)] | 45 | #[derive(Debug, Clone, PartialEq, Eq)] |
68 | pub struct EnumData { | 46 | pub struct EnumData { |
69 | name: Option<Name>, | 47 | pub(crate) name: Option<Name>, |
70 | variants: Vec<(Name, Arc<VariantData>)>, | 48 | pub(crate) variants: Vec<(Name, Arc<VariantData>)>, |
71 | } | 49 | } |
72 | 50 | ||
73 | impl EnumData { | 51 | impl EnumData { |
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 12947da2d..43bd2003c 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -114,6 +114,7 @@ impl Module { | |||
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
117 | pub struct Struct { | 118 | pub struct Struct { |
118 | pub(crate) def_id: DefId, | 119 | pub(crate) def_id: DefId, |
119 | } | 120 | } |
@@ -124,10 +125,29 @@ impl Struct { | |||
124 | } | 125 | } |
125 | 126 | ||
126 | pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | 127 | pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { |
127 | Ok(self.struct_data(db)?.variant_data.clone()) | 128 | Ok(db.struct_data(self.def_id)?.variant_data.clone()) |
128 | } | 129 | } |
129 | 130 | ||
130 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | 131 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { |
131 | Ok(self.struct_data(db)?.name.clone()) | 132 | Ok(db.struct_data(self.def_id)?.name.clone()) |
133 | } | ||
134 | } | ||
135 | |||
136 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
137 | pub struct Enum { | ||
138 | pub(crate) def_id: DefId, | ||
139 | } | ||
140 | |||
141 | impl Enum { | ||
142 | pub fn def_id(&self) -> DefId { | ||
143 | self.def_id | ||
144 | } | ||
145 | |||
146 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | ||
147 | Ok(db.enum_data(self.def_id)?.name.clone()) | ||
148 | } | ||
149 | |||
150 | pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> { | ||
151 | Ok(db.enum_data(self.def_id)?.variants.clone()) | ||
132 | } | 152 | } |
133 | } | 153 | } |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 9b66f5bb7..8eff2aea5 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -50,7 +50,6 @@ pub use self::{ | |||
50 | module_tree::ModuleId, | 50 | module_tree::ModuleId, |
51 | nameres::{ItemMap, PerNs, Namespace, Resolution}, | 51 | nameres::{ItemMap, PerNs, Namespace, Resolution}, |
52 | function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping}, | 52 | function::{Function, FnSignature, FnScopes, ScopesWithSyntaxMapping}, |
53 | adt::Enum, | ||
54 | ty::Ty, | 53 | ty::Ty, |
55 | impl_block::{ImplBlock, ImplItem}, | 54 | impl_block::{ImplBlock, ImplItem}, |
56 | }; | 55 | }; |
@@ -60,7 +59,7 @@ pub use self::function::FnSignatureInfo; | |||
60 | pub use self::code_model_api::{ | 59 | pub use self::code_model_api::{ |
61 | Crate, CrateDependency, | 60 | Crate, CrateDependency, |
62 | Module, ModuleSource, Problem, | 61 | Module, ModuleSource, Problem, |
63 | Struct, | 62 | Struct, Enum, |
64 | }; | 63 | }; |
65 | 64 | ||
66 | pub enum Def { | 65 | pub enum Def { |