From 45117c63884366ee82102a782a62a09fefff746b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Sep 2019 00:10:16 +0300 Subject: make various enums "inherit" from AdtDef --- crates/ra_ide_api/src/completion/complete_path.rs | 13 ++++--------- crates/ra_ide_api/src/completion/complete_pattern.rs | 2 +- crates/ra_ide_api/src/completion/presentation.rs | 12 +++++++++--- crates/ra_ide_api/src/display/navigation_target.rs | 4 +--- crates/ra_ide_api/src/hover.rs | 12 ++++++++---- crates/ra_ide_api/src/syntax_highlighting.rs | 4 +--- 6 files changed, 24 insertions(+), 23 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 457a3d10c..df14f465a 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,4 +1,4 @@ -use hir::{Either, Resolution}; +use hir::{AdtDef, Either, Resolution}; use ra_syntax::AstNode; use test_utils::tested_by; @@ -37,19 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); } } - hir::ModuleDef::Enum(_) - | hir::ModuleDef::Struct(_) - | hir::ModuleDef::Union(_) - | hir::ModuleDef::TypeAlias(_) => { - if let hir::ModuleDef::Enum(e) = def { + hir::ModuleDef::AdtDef(_) | hir::ModuleDef::TypeAlias(_) => { + if let hir::ModuleDef::AdtDef(AdtDef::Enum(e)) = def { for variant in e.variants(ctx.db) { acc.add_enum_variant(ctx, variant); } } let ty = match def { - hir::ModuleDef::Enum(e) => e.ty(ctx.db), - hir::ModuleDef::Struct(s) => s.ty(ctx.db), - hir::ModuleDef::Union(u) => u.ty(ctx.db), + hir::ModuleDef::AdtDef(adt) => adt.ty(ctx.db), hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), _ => unreachable!(), }; diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index fb02844fa..05db973e4 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -15,7 +15,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { _ => continue, }; match def { - hir::ModuleDef::Enum(..) + hir::ModuleDef::AdtDef(hir::AdtDef::Enum(..)) | hir::ModuleDef::EnumVariant(..) | hir::ModuleDef::Const(..) | hir::ModuleDef::Module(..) => (), diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 5cabe9a32..e9bf2b96d 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -67,9 +67,15 @@ impl Completions { Resolution::Def(Function(func)) => { return self.add_function_with_name(ctx, Some(local_name), *func); } - Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), - Resolution::Def(Union(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), - Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), + Resolution::Def(AdtDef(hir::AdtDef::Struct(it))) => { + (CompletionItemKind::Struct, it.docs(ctx.db)) + } + Resolution::Def(AdtDef(hir::AdtDef::Union(it))) => { + (CompletionItemKind::Struct, it.docs(ctx.db)) + } + Resolution::Def(AdtDef(hir::AdtDef::Enum(it))) => { + (CompletionItemKind::Enum, it.docs(ctx.db)) + } Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index c85214bb3..b8085f077 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -193,9 +193,7 @@ impl NavigationTarget { let nav = match module_def { hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), - hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), - hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), - hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), + hir::ModuleDef::AdtDef(it) => NavigationTarget::from_adt_def(db, it), hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 4b7847de8..f7b7cb8f8 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -1,4 +1,4 @@ -use hir::{HasSource, HirDisplay}; +use hir::{AdtDef, HasSource, HirDisplay}; use ra_db::SourceDatabase; use ra_syntax::{ algo::{ @@ -129,9 +129,13 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), - hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::AdtDef(AdtDef::Struct(it)) => { + res.extend(from_def_source(db, it)) + } + hir::ModuleDef::AdtDef(AdtDef::Union(it)) => { + res.extend(from_def_source(db, it)) + } + hir::ModuleDef::AdtDef(AdtDef::Enum(it)) => res.extend(from_def_source(db, it)), hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 06ccf0728..ee7531d37 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -107,9 +107,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "type", Some(Def(hir::ModuleDef::Module(_))) => "module", Some(Def(hir::ModuleDef::Function(_))) => "function", - Some(Def(hir::ModuleDef::Struct(_))) => "type", - Some(Def(hir::ModuleDef::Union(_))) => "type", - Some(Def(hir::ModuleDef::Enum(_))) => "type", + Some(Def(hir::ModuleDef::AdtDef(_))) => "type", Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", Some(Def(hir::ModuleDef::Const(_))) => "constant", Some(Def(hir::ModuleDef::Static(_))) => "constant", -- cgit v1.2.3 From 114a1b878e95c20490af574550ea0825b7a8f9d1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Sep 2019 00:34:52 +0300 Subject: rename AdtDef -> Adt --- crates/ra_ide_api/src/completion/complete_dot.rs | 4 ++-- crates/ra_ide_api/src/completion/complete_path.rs | 8 ++++---- crates/ra_ide_api/src/completion/complete_pattern.rs | 2 +- crates/ra_ide_api/src/completion/presentation.rs | 8 +++----- crates/ra_ide_api/src/display/navigation_target.rs | 10 +++++----- crates/ra_ide_api/src/hover.rs | 18 +++++++----------- crates/ra_ide_api/src/name_ref_kind.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 2 +- 8 files changed, 24 insertions(+), 30 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 2325cdf08..9e64c8659 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{AdtDef, Ty, TypeCtor}; +use hir::{Adt, Ty, TypeCtor}; use crate::completion::completion_item::CompletionKind; use crate::{ @@ -37,7 +37,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) for receiver in ctx.analyzer.autoderef(ctx.db, receiver) { if let Ty::Apply(a_ty) = receiver { match a_ty.ctor { - TypeCtor::Adt(AdtDef::Struct(s)) => { + TypeCtor::Adt(Adt::Struct(s)) => { for field in s.fields(ctx.db) { acc.add_field(ctx, field, &a_ty.parameters); } diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index df14f465a..4d3414f33 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,4 +1,4 @@ -use hir::{AdtDef, Either, Resolution}; +use hir::{Adt, Either, Resolution}; use ra_syntax::AstNode; use test_utils::tested_by; @@ -37,14 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); } } - hir::ModuleDef::AdtDef(_) | hir::ModuleDef::TypeAlias(_) => { - if let hir::ModuleDef::AdtDef(AdtDef::Enum(e)) = def { + hir::ModuleDef::Adt(_) | hir::ModuleDef::TypeAlias(_) => { + if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { for variant in e.variants(ctx.db) { acc.add_enum_variant(ctx, variant); } } let ty = match def { - hir::ModuleDef::AdtDef(adt) => adt.ty(ctx.db), + hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), _ => unreachable!(), }; diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index 05db973e4..fb7f9feb8 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -15,7 +15,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { _ => continue, }; match def { - hir::ModuleDef::AdtDef(hir::AdtDef::Enum(..)) + hir::ModuleDef::Adt(hir::Adt::Enum(..)) | hir::ModuleDef::EnumVariant(..) | hir::ModuleDef::Const(..) | hir::ModuleDef::Module(..) => (), diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index e9bf2b96d..95bbd34b7 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -67,15 +67,13 @@ impl Completions { Resolution::Def(Function(func)) => { return self.add_function_with_name(ctx, Some(local_name), *func); } - Resolution::Def(AdtDef(hir::AdtDef::Struct(it))) => { + Resolution::Def(Adt(hir::Adt::Struct(it))) => { (CompletionItemKind::Struct, it.docs(ctx.db)) } - Resolution::Def(AdtDef(hir::AdtDef::Union(it))) => { + Resolution::Def(Adt(hir::Adt::Union(it))) => { (CompletionItemKind::Struct, it.docs(ctx.db)) } - Resolution::Def(AdtDef(hir::AdtDef::Enum(it))) => { - (CompletionItemKind::Enum, it.docs(ctx.db)) - } + Resolution::Def(Adt(hir::Adt::Enum(it))) => (CompletionItemKind::Enum, it.docs(ctx.db)), Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index b8085f077..03382ab3c 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -178,11 +178,11 @@ impl NavigationTarget { ) } - pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { + pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::Adt) -> NavigationTarget { match adt_def { - hir::AdtDef::Struct(it) => NavigationTarget::from_def_source(db, it), - hir::AdtDef::Union(it) => NavigationTarget::from_def_source(db, it), - hir::AdtDef::Enum(it) => NavigationTarget::from_def_source(db, it), + hir::Adt::Struct(it) => NavigationTarget::from_def_source(db, it), + hir::Adt::Union(it) => NavigationTarget::from_def_source(db, it), + hir::Adt::Enum(it) => NavigationTarget::from_def_source(db, it), } } @@ -193,7 +193,7 @@ impl NavigationTarget { let nav = match module_def { hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), - hir::ModuleDef::AdtDef(it) => NavigationTarget::from_adt_def(db, it), + hir::ModuleDef::Adt(it) => NavigationTarget::from_adt_def(db, it), hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index f7b7cb8f8..28a6bef12 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -1,4 +1,4 @@ -use hir::{AdtDef, HasSource, HirDisplay}; +use hir::{Adt, HasSource, HirDisplay}; use ra_db::SourceDatabase; use ra_syntax::{ algo::{ @@ -129,13 +129,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), - hir::ModuleDef::AdtDef(AdtDef::Struct(it)) => { - res.extend(from_def_source(db, it)) - } - hir::ModuleDef::AdtDef(AdtDef::Union(it)) => { - res.extend(from_def_source(db, it)) - } - hir::ModuleDef::AdtDef(AdtDef::Enum(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)), hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), @@ -149,9 +145,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { if let Some((adt_def, _)) = ty.as_adt() { res.extend(match adt_def { - hir::AdtDef::Struct(it) => from_def_source(db, it), - hir::AdtDef::Union(it) => from_def_source(db, it), - hir::AdtDef::Enum(it) => from_def_source(db, it), + hir::Adt::Struct(it) => from_def_source(db, it), + hir::Adt::Union(it) => from_def_source(db, it), + hir::Adt::Enum(it) => from_def_source(db, it), }) } } diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 34a8bcc36..6c2a7b260 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs @@ -60,7 +60,7 @@ pub(crate) fn classify_name_ref( let record_lit = field_expr.syntax().ancestors().find_map(ast::RecordLit::cast); if let Some(ty) = record_lit.and_then(|lit| analyzer.type_of(db, &lit.into())) { - if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() { + if let Some((hir::Adt::Struct(s), _)) = ty.as_adt() { let hir_path = hir::Path::from_name_ref(name_ref); let hir_name = hir_path.as_ident().unwrap(); diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index ee7531d37..86ab3a260 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -107,7 +107,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "type", Some(Def(hir::ModuleDef::Module(_))) => "module", Some(Def(hir::ModuleDef::Function(_))) => "function", - Some(Def(hir::ModuleDef::AdtDef(_))) => "type", + Some(Def(hir::ModuleDef::Adt(_))) => "type", Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", Some(Def(hir::ModuleDef::Const(_))) => "constant", Some(Def(hir::ModuleDef::Static(_))) => "constant", -- cgit v1.2.3