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_db/src/defs.rs | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'crates/ra_ide_db') 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_db/src/defs.rs | 8 ++++---- crates/ra_ide_db/src/imports_locator.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide_db') 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