diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml index 2716a38cc..f345f1de8 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ra_ide_db/Cargo.toml | |||
@@ -26,6 +26,7 @@ ra_text_edit = { path = "../ra_text_edit" } | |||
26 | ra_db = { path = "../ra_db" } | 26 | ra_db = { path = "../ra_db" } |
27 | ra_prof = { path = "../ra_prof" } | 27 | ra_prof = { path = "../ra_prof" } |
28 | test_utils = { path = "../test_utils" } | 28 | test_utils = { path = "../test_utils" } |
29 | ra_hir_def = { path = "../ra_hir_def" } | ||
29 | 30 | ||
30 | # ra_ide should depend only on the top-level `hir` package. if you need | 31 | # ra_ide should depend only on the top-level `hir` package. if you need |
31 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 32 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index df56f2d9e..80c99935d 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -6,6 +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 | db::{DefDatabase, HirDatabase}, | ||
9 | Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, | 10 | Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, |
10 | Semantics, TypeParam, Visibility, | 11 | Semantics, TypeParam, Visibility, |
11 | }; | 12 | }; |
@@ -16,6 +17,7 @@ use ra_syntax::{ | |||
16 | }; | 17 | }; |
17 | 18 | ||
18 | use crate::RootDatabase; | 19 | use crate::RootDatabase; |
20 | use ra_hir_def::resolver::{HasResolver, Resolver}; | ||
19 | 21 | ||
20 | // FIXME: a more precise name would probably be `Symbol`? | 22 | // FIXME: a more precise name would probably be `Symbol`? |
21 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] | 23 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] |
@@ -76,6 +78,21 @@ impl Definition { | |||
76 | }; | 78 | }; |
77 | Some(name) | 79 | Some(name) |
78 | } | 80 | } |
81 | |||
82 | pub fn resolver<D: HirDatabase + DefDatabase>(&self, db: &D) -> Option<Resolver> { | ||
83 | use hir::VariantDef; | ||
84 | use ra_hir_def::*; | ||
85 | Some(match self { | ||
86 | Definition::ModuleDef(def) => def.resolver(db)?, | ||
87 | Definition::Field(field) => { | ||
88 | Into::<VariantId>::into(Into::<VariantDef>::into(field.parent_def(db))).resolver(db) | ||
89 | } | ||
90 | Definition::Macro(m) => Into::<ModuleId>::into(m.module(db)?).resolver(db), | ||
91 | Definition::SelfType(imp) => Into::<ImplId>::into(imp.clone()).resolver(db), | ||
92 | Definition::Local(local) => Into::<DefWithBodyId>::into(local.parent(db)).resolver(db), | ||
93 | Definition::TypeParam(tp) => Into::<ModuleId>::into(tp.module(db)).resolver(db), | ||
94 | }) | ||
95 | } | ||
79 | } | 96 | } |
80 | 97 | ||
81 | #[derive(Debug)] | 98 | #[derive(Debug)] |