diff options
Diffstat (limited to 'crates/ra_hir/src/adt.rs')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index a2d228593..ee270ac45 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
1 | use ra_syntax::{SmolStr, ast::{self, NameOwner}}; | 3 | use ra_syntax::{SmolStr, ast::{self, NameOwner}}; |
2 | 4 | ||
3 | use crate::{ | 5 | use crate::{ |
@@ -15,6 +17,14 @@ impl Struct { | |||
15 | Struct { def_id } | 17 | Struct { def_id } |
16 | } | 18 | } |
17 | 19 | ||
20 | pub fn def_id(&self) -> DefId { | ||
21 | self.def_id | ||
22 | } | ||
23 | |||
24 | pub fn struct_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<StructData>> { | ||
25 | Ok(db.struct_data(self.def_id)?) | ||
26 | } | ||
27 | |||
18 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<SmolStr> { | 28 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<SmolStr> { |
19 | Ok(db.struct_data(self.def_id)?.name.clone()) | 29 | Ok(db.struct_data(self.def_id)?.name.clone()) |
20 | } | 30 | } |
@@ -23,7 +33,7 @@ impl Struct { | |||
23 | #[derive(Debug, Clone, PartialEq, Eq)] | 33 | #[derive(Debug, Clone, PartialEq, Eq)] |
24 | pub struct StructData { | 34 | pub struct StructData { |
25 | name: SmolStr, | 35 | name: SmolStr, |
26 | variant_data: VariantData, | 36 | variant_data: Arc<VariantData>, |
27 | } | 37 | } |
28 | 38 | ||
29 | impl StructData { | 39 | impl StructData { |
@@ -33,8 +43,17 @@ impl StructData { | |||
33 | .map(|n| n.text()) | 43 | .map(|n| n.text()) |
34 | .unwrap_or(SmolStr::new("[error]")); | 44 | .unwrap_or(SmolStr::new("[error]")); |
35 | let variant_data = VariantData::Unit; // TODO implement this | 45 | let variant_data = VariantData::Unit; // TODO implement this |
46 | let variant_data = Arc::new(variant_data); | ||
36 | StructData { name, variant_data } | 47 | StructData { name, variant_data } |
37 | } | 48 | } |
49 | |||
50 | pub fn name(&self) -> &SmolStr { | ||
51 | &self.name | ||
52 | } | ||
53 | |||
54 | pub fn variant_data(&self) -> &Arc<VariantData> { | ||
55 | &self.variant_data | ||
56 | } | ||
38 | } | 57 | } |
39 | 58 | ||
40 | pub struct Enum { | 59 | pub struct Enum { |
@@ -46,6 +65,10 @@ impl Enum { | |||
46 | Enum { def_id } | 65 | Enum { def_id } |
47 | } | 66 | } |
48 | 67 | ||
68 | pub fn def_id(&self) -> DefId { | ||
69 | self.def_id | ||
70 | } | ||
71 | |||
49 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<SmolStr> { | 72 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<SmolStr> { |
50 | Ok(db.enum_data(self.def_id)?.name.clone()) | 73 | Ok(db.enum_data(self.def_id)?.name.clone()) |
51 | } | 74 | } |
@@ -54,7 +77,7 @@ impl Enum { | |||
54 | #[derive(Debug, Clone, PartialEq, Eq)] | 77 | #[derive(Debug, Clone, PartialEq, Eq)] |
55 | pub struct EnumData { | 78 | pub struct EnumData { |
56 | name: SmolStr, | 79 | name: SmolStr, |
57 | variants: Vec<(SmolStr, VariantData)>, | 80 | variants: Vec<(SmolStr, Arc<VariantData>)>, |
58 | } | 81 | } |
59 | 82 | ||
60 | impl EnumData { | 83 | impl EnumData { |