aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 4fc47aba5..249a4aba9 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -11,7 +11,7 @@ use crate::{
11 db::HirDatabase, 11 db::HirDatabase,
12 expr::BodySyntaxMapping, 12 expr::BodySyntaxMapping,
13 ty::{InferenceResult, VariantDef}, 13 ty::{InferenceResult, VariantDef},
14 adt::VariantData, 14 adt::{VariantData, EnumVariantId},
15 generics::GenericParams, 15 generics::GenericParams,
16 docs::{Documentation, Docs, docs_from_ast}, 16 docs::{Documentation, Docs, docs_from_ast},
17 module_tree::ModuleId, 17 module_tree::ModuleId,
@@ -252,8 +252,20 @@ impl Enum {
252 db.enum_data(*self).name.clone() 252 db.enum_data(*self).name.clone()
253 } 253 }
254 254
255 pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> { 255 pub fn variants(&self, db: &impl HirDatabase) -> Vec<EnumVariant> {
256 db.enum_data(*self).variants.clone() 256 db.enum_data(*self)
257 .variants
258 .iter()
259 .map(|(id, _)| EnumVariant { parent: *self, id })
260 .collect()
261 }
262
263 pub fn variant(&self, db: &impl HirDatabase, name: &Name) -> Option<EnumVariant> {
264 db.enum_data(*self)
265 .variants
266 .iter()
267 .find(|(_id, data)| data.name.as_ref() == Some(name))
268 .map(|(id, _)| EnumVariant { parent: *self, id })
257 } 269 }
258 270
259 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 271 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
@@ -270,7 +282,7 @@ impl Docs for Enum {
270#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 282#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
271pub struct EnumVariant { 283pub struct EnumVariant {
272 pub(crate) parent: Enum, 284 pub(crate) parent: Enum,
273 pub(crate) idx: u32, 285 pub(crate) id: EnumVariantId,
274} 286}
275 287
276impl EnumVariant { 288impl EnumVariant {
@@ -285,11 +297,13 @@ impl EnumVariant {
285 } 297 }
286 298
287 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 299 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
288 db.enum_variant_data(*self).name.clone() 300 db.enum_data(self.parent).variants[self.id].name.clone()
289 } 301 }
290 302
291 pub fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> { 303 pub fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
292 db.enum_variant_data(*self).variant_data.clone() 304 db.enum_data(self.parent).variants[self.id]
305 .variant_data
306 .clone()
293 } 307 }
294 308
295 pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> { 309 pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> {