From 828d60574f8ecbc33fe4987913c6f713e41af1ae Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 14 Sep 2019 16:26:03 +0200 Subject: Refactor a bit to prepare for resolving trait assoc items --- crates/ra_ide_api/src/display/navigation_target.rs | 15 +++++++++------ crates/ra_ide_api/src/goto_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 6 +++--- crates/ra_ide_api/src/name_ref_kind.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 03382ab3c..11f73ccfd 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -1,4 +1,4 @@ -use hir::{FieldSource, HasSource, ImplItem, ModuleSource}; +use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ algo::visit::{visitor, Visitor}, @@ -221,11 +221,14 @@ impl NavigationTarget { ) } - pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget { - match impl_item { - ImplItem::Method(it) => NavigationTarget::from_def_source(db, it), - ImplItem::Const(it) => NavigationTarget::from_def_source(db, it), - ImplItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it), + pub(crate) fn from_assoc_item( + db: &RootDatabase, + assoc_item: hir::AssocItem, + ) -> NavigationTarget { + match assoc_item { + AssocItem::Function(it) => NavigationTarget::from_def_source(db, it), + AssocItem::Const(it) => NavigationTarget::from_def_source(db, it), + AssocItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it), } } diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 28529a2de..503dcacff 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -60,7 +60,7 @@ pub(crate) fn reference_definition( match classify_name_ref(db, &analyzer, name_ref) { Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)), Some(FieldAccess(field)) => return Exact(NavigationTarget::from_field(db, field)), - Some(AssocItem(assoc)) => return Exact(NavigationTarget::from_impl_item(db, assoc)), + Some(AssocItem(assoc)) => return Exact(NavigationTarget::from_assoc_item(db, assoc)), Some(Method(func)) => return Exact(NavigationTarget::from_def_source(db, func)), Some(Def(def)) => match NavigationTarget::from_def(db, def) { Some(nav) => return Exact(nav), diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 28a6bef12..655bcdb16 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -117,9 +117,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(match it { - hir::ImplItem::Method(it) => from_def_source(db, it), - hir::ImplItem::Const(it) => from_def_source(db, it), - hir::ImplItem::TypeAlias(it) => from_def_source(db, it), + hir::AssocItem::Function(it) => from_def_source(db, it), + hir::AssocItem::Const(it) => from_def_source(db, it), + hir::AssocItem::TypeAlias(it) => from_def_source(db, it), }), Some(Def(it)) => { match it { diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 6c2a7b260..aff03464a 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs @@ -8,7 +8,7 @@ pub enum NameRefKind { Method(hir::Function), Macro(hir::MacroDef), FieldAccess(hir::StructField), - AssocItem(hir::ImplItem), + AssocItem(hir::AssocItem), Def(hir::ModuleDef), SelfType(hir::Ty), Pat(AstPtr), diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 86ab3a260..3d7f91c1d 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -102,9 +102,9 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "function", Some(Macro(_)) => "macro", Some(FieldAccess(_)) => "field", - Some(AssocItem(hir::ImplItem::Method(_))) => "function", - Some(AssocItem(hir::ImplItem::Const(_))) => "constant", - Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type", + Some(AssocItem(hir::AssocItem::Function(_))) => "function", + Some(AssocItem(hir::AssocItem::Const(_))) => "constant", + Some(AssocItem(hir::AssocItem::TypeAlias(_))) => "type", Some(Def(hir::ModuleDef::Module(_))) => "module", Some(Def(hir::ModuleDef::Function(_))) => "function", Some(Def(hir::ModuleDef::Adt(_))) => "type", -- cgit v1.2.3