From 978de5cf8bfd2ff82696fc8d5369b41e147431c3 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Tue, 8 Jan 2019 16:01:19 +0100 Subject: Implement type inference for enum variants --- crates/ra_ide_api/src/completion/complete_path.rs | 22 ++++++++++++++-------- crates/ra_ide_api/src/db.rs | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 4723a65a6..6a55670d1 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -21,14 +21,20 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C .add_to(acc) }); } - hir::Def::Enum(e) => e - .variants(ctx.db)? - .into_iter() - .for_each(|(name, _variant)| { - CompletionItem::new(CompletionKind::Reference, name.to_string()) - .kind(CompletionItemKind::EnumVariant) - .add_to(acc) - }), + hir::Def::Enum(e) => { + e.variants(ctx.db)? + .unwrap_or(vec![]) + .into_iter() + .for_each(|variant| { + let variant_name = variant.name(ctx.db); + + if let Ok(Some(name)) = variant_name { + CompletionItem::new(CompletionKind::Reference, name.to_string()) + .kind(CompletionItemKind::EnumVariant) + .add_to(acc) + } + }) + } _ => return Ok(()), }; Ok(()) diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index a2e06f5db..efdf261be 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -122,6 +122,7 @@ salsa::database_storage! { fn type_for_field() for hir::db::TypeForFieldQuery; fn struct_data() for hir::db::StructDataQuery; fn enum_data() for hir::db::EnumDataQuery; + fn enum_variant_data() for hir::db::EnumVariantDataQuery; fn impls_in_module() for hir::db::ImplsInModuleQuery; fn body_hir() for hir::db::BodyHirQuery; fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery; -- cgit v1.2.3 From e78286c8e88d31045d354320a1d29bbd75405027 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Thu, 10 Jan 2019 02:07:42 +0100 Subject: Save variant names in EnumData to reduce needless queries We already have their names when anyway, and when in all (current) situations where we're interested in an Enum's variants, we want their names. --- crates/ra_ide_api/src/completion/complete_path.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 6a55670d1..9bfec88d0 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -23,17 +23,12 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C } hir::Def::Enum(e) => { e.variants(ctx.db)? - .unwrap_or(vec![]) .into_iter() - .for_each(|variant| { - let variant_name = variant.name(ctx.db); - - if let Ok(Some(name)) = variant_name { - CompletionItem::new(CompletionKind::Reference, name.to_string()) - .kind(CompletionItemKind::EnumVariant) - .add_to(acc) - } - }) + .for_each(|(variant_name, _variant)| { + CompletionItem::new(CompletionKind::Reference, variant_name.to_string()) + .kind(CompletionItemKind::EnumVariant) + .add_to(acc) + }); } _ => return Ok(()), }; -- cgit v1.2.3