From 7d71cc72b5902300ed03db409b2a858517a1f5e0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 3 Mar 2020 18:22:52 +0100 Subject: Refactor reference search a bit --- crates/ra_ide_db/src/defs.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (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 7b1030a14..8a5161dfe 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, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Semantics, + Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Name, Semantics, StructField, TypeParam, }; use ra_prof::profile; @@ -66,6 +66,32 @@ impl NameDefinition { NameDefinition::TypeParam(_) => None, } } + + pub fn name(&self, db: &RootDatabase) -> Option { + let name = match self { + NameDefinition::Macro(it) => it.name(db)?, + NameDefinition::StructField(it) => it.name(db), + NameDefinition::ModuleDef(def) => match def { + hir::ModuleDef::Module(it) => it.name(db)?, + hir::ModuleDef::Function(it) => it.name(db), + hir::ModuleDef::Adt(def) => match def { + hir::Adt::Struct(it) => it.name(db), + hir::Adt::Union(it) => it.name(db), + hir::Adt::Enum(it) => it.name(db), + }, + hir::ModuleDef::EnumVariant(it) => it.name(db), + hir::ModuleDef::Const(it) => it.name(db)?, + hir::ModuleDef::Static(it) => it.name(db)?, + hir::ModuleDef::Trait(it) => it.name(db), + hir::ModuleDef::TypeAlias(it) => it.name(db), + hir::ModuleDef::BuiltinType(_) => return None, + }, + NameDefinition::SelfType(_) => return None, + NameDefinition::Local(it) => it.name(db)?, + NameDefinition::TypeParam(it) => it.name(db), + }; + Some(name) + } } pub enum NameClass { -- cgit v1.2.3