aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/adt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/adt.rs')
-rw-r--r--crates/ra_hir/src/adt.rs27
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 @@
1use std::sync::Arc;
2
1use ra_syntax::{SmolStr, ast::{self, NameOwner}}; 3use ra_syntax::{SmolStr, ast::{self, NameOwner}};
2 4
3use crate::{ 5use 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)]
24pub struct StructData { 34pub struct StructData {
25 name: SmolStr, 35 name: SmolStr,
26 variant_data: VariantData, 36 variant_data: Arc<VariantData>,
27} 37}
28 38
29impl StructData { 39impl 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
40pub struct Enum { 59pub 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)]
55pub struct EnumData { 78pub struct EnumData {
56 name: SmolStr, 79 name: SmolStr,
57 variants: Vec<(SmolStr, VariantData)>, 80 variants: Vec<(SmolStr, Arc<VariantData>)>,
58} 81}
59 82
60impl EnumData { 83impl EnumData {