aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 12:22:57 +0000
committerAleksey Kladov <[email protected]>2019-01-08 12:22:57 +0000
commit2d4dc22af8db8f9ebb5f2e95cd25c473494a4b70 (patch)
tree963dfadfe92595982ba0c374e467bdbb41d04c3d /crates/ra_hir
parente30c533eb67ba8a24708a94385849854c17e67f9 (diff)
move enum to code_model_api
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs28
-rw-r--r--crates/ra_hir/src/code_model_api.rs24
-rw-r--r--crates/ra_hir/src/lib.rs3
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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_db::Cancelable;
4use ra_syntax::ast::{self, NameOwner, StructFlavor}; 3use ra_syntax::ast::{self, NameOwner, StructFlavor};
5 4
6use crate::{ 5use 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
45pub struct Enum {
46 def_id: DefId,
47}
48
49impl Enum { 39impl 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)]
68pub struct EnumData { 46pub 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
73impl EnumData { 51impl 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)]
117pub struct Struct { 118pub 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)]
137pub struct Enum {
138 pub(crate) def_id: DefId,
139}
140
141impl 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;
60pub use self::code_model_api::{ 59pub 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
66pub enum Def { 65pub enum Def {