aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src/defs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db/src/defs.rs')
-rw-r--r--crates/ra_ide_db/src/defs.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 3ef5e74b6..a158169e3 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -7,7 +7,7 @@
7 7
8use hir::{ 8use hir::{
9 Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, 9 Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution,
10 Semantics, TypeParam, Visibility, 10 Semantics, TypeParam, Visibility, db::{DefDatabase, HirDatabase},
11}; 11};
12use ra_prof::profile; 12use ra_prof::profile;
13use ra_syntax::{ 13use ra_syntax::{
@@ -16,6 +16,7 @@ use ra_syntax::{
16}; 16};
17 17
18use crate::RootDatabase; 18use crate::RootDatabase;
19use ra_hir_def::resolver::{Resolver, HasResolver};
19 20
20// FIXME: a more precise name would probably be `Symbol`? 21// FIXME: a more precise name would probably be `Symbol`?
21#[derive(Debug, PartialEq, Eq, Copy, Clone)] 22#[derive(Debug, PartialEq, Eq, Copy, Clone)]
@@ -76,6 +77,20 @@ impl Definition {
76 }; 77 };
77 Some(name) 78 Some(name)
78 } 79 }
80
81 pub fn resolver<D: HirDatabase + DefDatabase>(&self, db: &D) -> Option<Resolver> {
82 use hir::VariantDef;
83 use ra_hir_def::*;
84 Some(match self {
85 Definition::ModuleDef(def) => def.resolver(db)?,
86 Definition::Field(field) => Into::<VariantId>::into(Into::<VariantDef>::into(field.parent_def(db))).resolver(db),
87 Definition::Macro(m) => Into::<ModuleId>::into(m.module(db)?).resolver(db),
88 Definition::SelfType(imp) => Into::<ImplId>::into(imp.clone()).resolver(db),
89 // it's possible, read probable, that other arms of this are also unreachable
90 Definition::Local(_local) => unreachable!(),
91 Definition::TypeParam(tp) => Into::<ModuleId>::into(tp.module(db)).resolver(db)
92 })
93 }
79} 94}
80 95
81#[derive(Debug)] 96#[derive(Debug)]