aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db
diff options
context:
space:
mode:
authorZac Pullar-Strecker <[email protected]>2020-06-13 11:34:59 +0100
committerZac Pullar-Strecker <[email protected]>2020-06-30 09:07:08 +0100
commit1d6f291335c58aac95c1124f55d7fb0834baff2a (patch)
treef0d64776e584bf40ba8edb638596a5a03bf04002 /crates/ra_ide_db
parent108b953254e46851130e427b41cd143eee07fd02 (diff)
Move resolver into impls, work on tests
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r--crates/ra_ide_db/Cargo.toml1
-rw-r--r--crates/ra_ide_db/src/defs.rs17
2 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml
index c3921bd40..b14206c9b 100644
--- a/crates/ra_ide_db/Cargo.toml
+++ b/crates/ra_ide_db/Cargo.toml
@@ -24,6 +24,7 @@ ra_text_edit = { path = "../ra_text_edit" }
24ra_db = { path = "../ra_db" } 24ra_db = { path = "../ra_db" }
25ra_prof = { path = "../ra_prof" } 25ra_prof = { path = "../ra_prof" }
26test_utils = { path = "../test_utils" } 26test_utils = { path = "../test_utils" }
27ra_hir_def = { path = "../ra_hir_def" }
27 28
28# ra_ide should depend only on the top-level `hir` package. if you need 29# ra_ide should depend only on the top-level `hir` package. if you need
29# something from some `hir_xxx` subpackage, reexport the API via `hir`. 30# 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 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)]