diff options
Diffstat (limited to 'crates/ra_hir_def/src/adt.rs')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 22bd469f0..8f41e55d2 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId, | 10 | db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId, |
11 | LocalStructFieldId, StructId, | 11 | LocalStructFieldId, StructId, UnionId, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | /// Note that we use `StructData` for unions as well! | 14 | /// Note that we use `StructData` for unions as well! |
@@ -56,6 +56,13 @@ impl StructData { | |||
56 | let variant_data = Arc::new(variant_data); | 56 | let variant_data = Arc::new(variant_data); |
57 | Arc::new(StructData { name, variant_data }) | 57 | Arc::new(StructData { name, variant_data }) |
58 | } | 58 | } |
59 | pub(crate) fn union_data_query(db: &impl DefDatabase2, struct_: UnionId) -> Arc<StructData> { | ||
60 | let src = struct_.source(db); | ||
61 | let name = src.ast.name().map(|n| n.as_name()); | ||
62 | let variant_data = VariantData::new(src.ast.kind()); | ||
63 | let variant_data = Arc::new(variant_data); | ||
64 | Arc::new(StructData { name, variant_data }) | ||
65 | } | ||
59 | } | 66 | } |
60 | 67 | ||
61 | impl EnumData { | 68 | impl EnumData { |
@@ -74,6 +81,11 @@ impl EnumData { | |||
74 | .collect(); | 81 | .collect(); |
75 | Arc::new(EnumData { name, variants }) | 82 | Arc::new(EnumData { name, variants }) |
76 | } | 83 | } |
84 | |||
85 | pub(crate) fn variant(&self, name: &Name) -> Option<LocalEnumVariantId> { | ||
86 | let (id, _) = self.variants.iter().find(|(_id, data)| data.name.as_ref() == Some(name))?; | ||
87 | Some(id) | ||
88 | } | ||
77 | } | 89 | } |
78 | 90 | ||
79 | impl VariantData { | 91 | impl VariantData { |