diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-03 17:23:39 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-03 17:23:39 +0000 |
commit | 13b25d73b56ede36d1680efc19f5c11b0669b96c (patch) | |
tree | 4a7bd4db725448629adcda067452a85854a61ff1 /crates/ra_ide_db | |
parent | cebb995d21e18990939287f55628237563583b27 (diff) | |
parent | 7d71cc72b5902300ed03db409b2a858517a1f5e0 (diff) |
Merge #3426
3426: Refactor reference search a bit r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
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 { |