diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 28 |
1 files changed, 27 insertions, 1 deletions
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 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Semantics, | 9 | Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Name, Semantics, |
10 | StructField, TypeParam, | 10 | StructField, TypeParam, |
11 | }; | 11 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
@@ -66,6 +66,32 @@ impl NameDefinition { | |||
66 | NameDefinition::TypeParam(_) => None, | 66 | NameDefinition::TypeParam(_) => None, |
67 | } | 67 | } |
68 | } | 68 | } |
69 | |||
70 | pub fn name(&self, db: &RootDatabase) -> Option<Name> { | ||
71 | let name = match self { | ||
72 | NameDefinition::Macro(it) => it.name(db)?, | ||
73 | NameDefinition::StructField(it) => it.name(db), | ||
74 | NameDefinition::ModuleDef(def) => match def { | ||
75 | hir::ModuleDef::Module(it) => it.name(db)?, | ||
76 | hir::ModuleDef::Function(it) => it.name(db), | ||
77 | hir::ModuleDef::Adt(def) => match def { | ||
78 | hir::Adt::Struct(it) => it.name(db), | ||
79 | hir::Adt::Union(it) => it.name(db), | ||
80 | hir::Adt::Enum(it) => it.name(db), | ||
81 | }, | ||
82 | hir::ModuleDef::EnumVariant(it) => it.name(db), | ||
83 | hir::ModuleDef::Const(it) => it.name(db)?, | ||
84 | hir::ModuleDef::Static(it) => it.name(db)?, | ||
85 | hir::ModuleDef::Trait(it) => it.name(db), | ||
86 | hir::ModuleDef::TypeAlias(it) => it.name(db), | ||
87 | hir::ModuleDef::BuiltinType(_) => return None, | ||
88 | }, | ||
89 | NameDefinition::SelfType(_) => return None, | ||
90 | NameDefinition::Local(it) => it.name(db)?, | ||
91 | NameDefinition::TypeParam(it) => it.name(db), | ||
92 | }; | ||
93 | Some(name) | ||
94 | } | ||
69 | } | 95 | } |
70 | 96 | ||
71 | pub enum NameClass { | 97 | pub enum NameClass { |