diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-03 21:34:50 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-03 21:34:50 +0000 |
commit | 4fd742d6bc23e2f61d0980e15234f09d7e715b76 (patch) | |
tree | c37d38f9313f54ea71580f6bd005f554388a57ab /crates/ra_hir_def/src/adt.rs | |
parent | f9f1effd011b906903891c09f1cb6b2a42f73e95 (diff) | |
parent | 8922a44395482896fec0c0a47a7fac4612112d45 (diff) |
Merge #2163
2163: Move CrateDefMap to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
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 { |