aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-08 22:05:49 +0000
committerAleksey Kladov <[email protected]>2018-12-09 10:33:16 +0000
commit74fe581061be5175835efda69ee1fa3817716a59 (patch)
tree05f062ffbdc1d81229bae6abbd9b015ea28f9793 /crates
parent961cae7e53a05625f3e010076673ca083479b481 (diff)
return dependencies with names
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs4
-rw-r--r--crates/ra_hir/src/krate.rs19
2 files changed, 17 insertions, 6 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 44c5bac93..ac144b991 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -38,8 +38,8 @@ impl CrateData {
38 38
39#[derive(Debug, Clone, PartialEq, Eq)] 39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct Dependency { 40pub struct Dependency {
41 crate_id: CrateId, 41 pub crate_id: CrateId,
42 name: SmolStr, 42 pub name: SmolStr,
43} 43}
44 44
45impl Dependency { 45impl Dependency {
diff --git a/crates/ra_hir/src/krate.rs b/crates/ra_hir/src/krate.rs
index 61007cc29..1196dcef1 100644
--- a/crates/ra_hir/src/krate.rs
+++ b/crates/ra_hir/src/krate.rs
@@ -1,7 +1,8 @@
1use crate::{HirDatabase, Module, Cancelable}; 1use ra_syntax::SmolStr;
2
3pub use ra_db::CrateId; 2pub use ra_db::CrateId;
4 3
4use crate::{HirDatabase, Module, Cancelable};
5
5/// hir::Crate describes a single crate. It's the main inteface with which 6/// hir::Crate describes a single crate. It's the main inteface with which
6/// crate's dependencies interact. Mostly, it should be just a proxy for the 7/// crate's dependencies interact. Mostly, it should be just a proxy for the
7/// root module. 8/// root module.
@@ -10,15 +11,25 @@ pub struct Crate {
10 crate_id: CrateId, 11 crate_id: CrateId,
11} 12}
12 13
14#[derive(Debug)]
15pub struct CrateDependency {
16 pub krate: Crate,
17 pub name: SmolStr,
18}
19
13impl Crate { 20impl Crate {
14 pub(crate) fn new(crate_id: CrateId) -> Crate { 21 pub(crate) fn new(crate_id: CrateId) -> Crate {
15 Crate { crate_id } 22 Crate { crate_id }
16 } 23 }
17 pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<Crate> { 24 pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
18 let crate_graph = db.crate_graph(); 25 let crate_graph = db.crate_graph();
19 crate_graph 26 crate_graph
20 .dependencies(self.crate_id) 27 .dependencies(self.crate_id)
21 .map(|dep| Crate::new(dep.crate_id())) 28 .map(|dep| {
29 let krate = Crate::new(dep.crate_id());
30 let name = dep.name.clone();
31 CrateDependency { krate, name }
32 })
22 .collect() 33 .collect()
23 } 34 }
24 pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 35 pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {