From f55be75a17dab2ca23b34c45e7597fe19a5fc8e4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 7 Feb 2020 12:51:12 +0100 Subject: Remove irrelevant distinction --- crates/ra_ide/src/goto_definition.rs | 1 - crates/ra_ide/src/hover.rs | 5 ----- crates/ra_ide/src/references.rs | 1 - crates/ra_ide/src/references/classify.rs | 28 ++++++++++++++++++---------- crates/ra_ide/src/syntax_highlighting.rs | 3 --- crates/ra_ide_db/src/defs.rs | 32 ++++---------------------------- 6 files changed, 22 insertions(+), 48 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index e9329a72c..080cc302b 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -78,7 +78,6 @@ pub(crate) fn reference_definition( Some(Macro(it)) => return Exact(it.to_nav(sb.db)), Some(Field(it)) => return Exact(it.to_nav(sb.db)), Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), - Some(AssocItem(it)) => return Exact(it.to_nav(sb.db)), Some(Local(it)) => return Exact(it.to_nav(sb.db)), Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) { Some(nav) => return Exact(nav), diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 315b88190..ab3f513f2 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -105,11 +105,6 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option None, } } - AssocItem(it) => match 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), - }, Def(it) => match it { hir::ModuleDef::Module(it) => match it.definition_source(db).value { hir::ModuleSource::Module(it) => { diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index c215040f4..612ed84b7 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -128,7 +128,6 @@ pub(crate) fn find_all_refs( let declaration = match def.kind { NameKind::Macro(mac) => mac.to_nav(db), NameKind::Field(field) => field.to_nav(db), - NameKind::AssocItem(assoc) => assoc.to_nav(db), NameKind::Def(def) => NavigationTarget::from_def(db, def)?, NameKind::SelfType(imp) => imp.to_nav(db), NameKind::Local(local) => local.to_nav(db), diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 0326fd379..d0f03d8a8 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -8,7 +8,7 @@ use test_utils::tested_by; use super::{NameDefinition, NameKind}; use ra_ide_db::RootDatabase; -pub use ra_ide_db::defs::{classify_name, from_assoc_item, from_module_def, from_struct_field}; +pub use ra_ide_db::defs::{classify_name, from_module_def, from_struct_field}; pub(crate) fn classify_name_ref( sb: &mut SourceBinder, @@ -22,7 +22,7 @@ pub(crate) fn classify_name_ref( if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { tested_by!(goto_def_for_methods); if let Some(func) = analyzer.resolve_method_call(&method_call) { - return Some(from_assoc_item(sb.db, func.into())); + return Some(from_module_def(sb.db, func.into(), None)); } } @@ -57,27 +57,35 @@ pub(crate) fn classify_name_ref( let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; let resolved = analyzer.resolve_path(sb.db, &path)?; - match resolved { - PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))), - PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)), + let res = match resolved { + PathResolution::Def(def) => from_module_def(sb.db, def, Some(container)), + PathResolution::AssocItem(item) => { + let def = match item { + hir::AssocItem::Function(it) => it.into(), + hir::AssocItem::Const(it) => it.into(), + hir::AssocItem::TypeAlias(it) => it.into(), + }; + from_module_def(sb.db, def, Some(container)) + } PathResolution::Local(local) => { let kind = NameKind::Local(local); let container = local.module(sb.db); - Some(NameDefinition { kind, container, visibility: None }) + NameDefinition { kind, container, visibility: None } } PathResolution::TypeParam(par) => { let kind = NameKind::TypeParam(par); let container = par.module(sb.db); - Some(NameDefinition { kind, container, visibility }) + NameDefinition { kind, container, visibility } } PathResolution::Macro(def) => { let kind = NameKind::Macro(def); - Some(NameDefinition { kind, container, visibility }) + NameDefinition { kind, container, visibility } } PathResolution::SelfType(impl_block) => { let kind = NameKind::SelfType(impl_block); let container = impl_block.module(sb.db); - Some(NameDefinition { kind, container, visibility }) + NameDefinition { kind, container, visibility } } - } + }; + Some(res) } diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index c5d249fe8..c970f5d34 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -321,9 +321,6 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { match name_kind { Macro(_) => tags::MACRO, Field(_) => tags::FIELD, - AssocItem(hir::AssocItem::Function(_)) => tags::FUNCTION, - AssocItem(hir::AssocItem::Const(_)) => tags::CONSTANT, - AssocItem(hir::AssocItem::TypeAlias(_)) => tags::TYPE, Def(hir::ModuleDef::Module(_)) => tags::MODULE, Def(hir::ModuleDef::Function(_)) => tags::FUNCTION, Def(hir::ModuleDef::Adt(_)) => tags::TYPE, diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 788906723..0599f5e38 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -6,7 +6,7 @@ // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). use hir::{ - Adt, AssocItem, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder, + Adt, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder, StructField, TypeParam, VariantDef, }; use ra_prof::profile; @@ -21,7 +21,6 @@ use crate::RootDatabase; pub enum NameKind { Macro(MacroDef), Field(StructField), - AssocItem(AssocItem), Def(ModuleDef), SelfType(ImplBlock), Local(Local), @@ -92,29 +91,17 @@ pub fn classify_name( ast::FnDef(it) => { let src = name.with_value(it); let def: hir::Function = sb.to_def(src)?; - if parent.parent().and_then(ast::ItemList::cast).map_or(false, |it| it.syntax().parent().and_then(ast::Module::cast).is_none()) { - Some(from_assoc_item(sb.db, def.into())) - } else { - Some(from_module_def(sb.db, def.into(), None)) - } + Some(from_module_def(sb.db, def.into(), None)) }, ast::ConstDef(it) => { let src = name.with_value(it); let def: hir::Const = sb.to_def(src)?; - if parent.parent().and_then(ast::ItemList::cast).is_some() { - Some(from_assoc_item(sb.db, def.into())) - } else { - Some(from_module_def(sb.db, def.into(), None)) - } + Some(from_module_def(sb.db, def.into(), None)) }, ast::TypeAliasDef(it) => { let src = name.with_value(it); let def: hir::TypeAlias = sb.to_def(src)?; - if parent.parent().and_then(ast::ItemList::cast).is_some() { - Some(from_assoc_item(sb.db, def.into())) - } else { - Some(from_module_def(sb.db, def.into(), None)) - } + Some(from_module_def(sb.db, def.into(), None)) }, ast::MacroCall(it) => { let src = name.with_value(it); @@ -142,17 +129,6 @@ pub fn classify_name( } } -pub fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { - let container = item.module(db); - let visibility = match item { - AssocItem::Function(f) => f.source(db).value.visibility(), - AssocItem::Const(c) => c.source(db).value.visibility(), - AssocItem::TypeAlias(a) => a.source(db).value.visibility(), - }; - let kind = NameKind::AssocItem(item); - NameDefinition { kind, container, visibility } -} - pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { let kind = NameKind::Field(field); let parent = field.parent_def(db); -- cgit v1.2.3 From ae70d072374f3c4d14abdccbe61661cf02b41b33 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 7 Feb 2020 14:26:59 +0100 Subject: Rename --- crates/ra_ide/src/goto_definition.rs | 4 ++-- crates/ra_ide/src/hover.rs | 4 ++-- crates/ra_ide/src/references.rs | 8 ++++---- crates/ra_ide/src/syntax_highlighting.rs | 20 ++++++++++---------- crates/ra_ide_db/src/defs.rs | 8 ++++---- crates/ra_ide_db/src/imports_locator.rs | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 080cc302b..de5551a4c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -76,10 +76,10 @@ pub(crate) fn reference_definition( let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind); match name_kind { Some(Macro(it)) => return Exact(it.to_nav(sb.db)), - Some(Field(it)) => return Exact(it.to_nav(sb.db)), + Some(StructField(it)) => return Exact(it.to_nav(sb.db)), Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), Some(Local(it)) => return Exact(it.to_nav(sb.db)), - Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) { + Some(ModuleDef(def)) => match NavigationTarget::from_def(sb.db, def) { Some(nav) => return Exact(nav), None => return Approximate(vec![]), }, diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index ab3f513f2..3f88bb260 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -98,14 +98,14 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option { + StructField(it) => { let src = it.source(db); match src.value { hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), _ => None, } } - Def(it) => match it { + ModuleDef(it) => match it { hir::ModuleDef::Module(it) => match it.definition_source(db).value { hir::ModuleSource::Module(it) => { hover_text(it.doc_comment_text(), it.short_label()) diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 612ed84b7..a6320bd2f 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -127,8 +127,8 @@ pub(crate) fn find_all_refs( let declaration = match def.kind { NameKind::Macro(mac) => mac.to_nav(db), - NameKind::Field(field) => field.to_nav(db), - NameKind::Def(def) => NavigationTarget::from_def(db, def)?, + NameKind::StructField(field) => field.to_nav(db), + NameKind::ModuleDef(def) => NavigationTarget::from_def(db, def)?, NameKind::SelfType(imp) => imp.to_nav(db), NameKind::Local(local) => local.to_nav(db), NameKind::TypeParam(_) => return None, @@ -239,7 +239,7 @@ fn decl_access( range: TextRange, ) -> Option { match kind { - NameKind::Local(_) | NameKind::Field(_) => {} + NameKind::Local(_) | NameKind::StructField(_) => {} _ => return None, }; @@ -259,7 +259,7 @@ fn decl_access( fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option { // Only Locals and Fields have accesses for now. match kind { - NameKind::Local(_) | NameKind::Field(_) => {} + NameKind::Local(_) | NameKind::StructField(_) => {} _ => return None, }; diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index c970f5d34..174e13595 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -320,16 +320,16 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { match name_kind { Macro(_) => tags::MACRO, - Field(_) => tags::FIELD, - Def(hir::ModuleDef::Module(_)) => tags::MODULE, - Def(hir::ModuleDef::Function(_)) => tags::FUNCTION, - Def(hir::ModuleDef::Adt(_)) => tags::TYPE, - Def(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, - Def(hir::ModuleDef::Const(_)) => tags::CONSTANT, - Def(hir::ModuleDef::Static(_)) => tags::CONSTANT, - Def(hir::ModuleDef::Trait(_)) => tags::TYPE, - Def(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, - Def(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, + StructField(_) => tags::FIELD, + ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, + ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, + ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, + ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, + ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, + ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, + ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, + ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, + ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, SelfType(_) => tags::TYPE_SELF, TypeParam(_) => tags::TYPE_PARAM, Local(local) => { diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 0599f5e38..030f44f86 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -20,8 +20,8 @@ use crate::RootDatabase; #[derive(Debug, PartialEq, Eq)] pub enum NameKind { Macro(MacroDef), - Field(StructField), - Def(ModuleDef), + StructField(StructField), + ModuleDef(ModuleDef), SelfType(ImplBlock), Local(Local), TypeParam(TypeParam), @@ -130,7 +130,7 @@ pub fn classify_name( } pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { - let kind = NameKind::Field(field); + let kind = NameKind::StructField(field); let parent = field.parent_def(db); let container = parent.module(db); let visibility = match parent { @@ -146,7 +146,7 @@ pub fn from_module_def( def: ModuleDef, module: Option, ) -> NameDefinition { - let kind = NameKind::Def(def); + let kind = NameKind::ModuleDef(def); let (container, visibility) = match def { ModuleDef::Module(it) => { let container = it.parent(db).or_else(|| Some(it)).unwrap(); diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 401b8ac0b..86383bcd0 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs @@ -44,7 +44,7 @@ impl<'a> ImportsLocator<'a> { .chain(lib_results.into_iter()) .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) .filter_map(|name_definition_to_import| match name_definition_to_import { - NameKind::Def(module_def) => Some(module_def), + NameKind::ModuleDef(module_def) => Some(module_def), _ => None, }) .collect() -- cgit v1.2.3