From 74fe581061be5175835efda69ee1fa3817716a59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 01:05:49 +0300 Subject: [PATCH] return dependencies with names --- crates/ra_db/src/input.rs | 4 ++-- crates/ra_hir/src/krate.rs | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 44c5bac932..ac144b9918 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -38,8 +38,8 @@ impl CrateData { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { - crate_id: CrateId, - name: SmolStr, + pub crate_id: CrateId, + pub name: SmolStr, } impl Dependency { diff --git a/crates/ra_hir/src/krate.rs b/crates/ra_hir/src/krate.rs index 61007cc29a..1196dcef17 100644 --- a/crates/ra_hir/src/krate.rs +++ b/crates/ra_hir/src/krate.rs @@ -1,7 +1,8 @@ -use crate::{HirDatabase, Module, Cancelable}; - +use ra_syntax::SmolStr; pub use ra_db::CrateId; +use crate::{HirDatabase, Module, Cancelable}; + /// hir::Crate describes a single crate. It's the main inteface with which /// crate's dependencies interact. Mostly, it should be just a proxy for the /// root module. @@ -10,15 +11,25 @@ pub struct Crate { crate_id: CrateId, } +#[derive(Debug)] +pub struct CrateDependency { + pub krate: Crate, + pub name: SmolStr, +} + impl Crate { pub(crate) fn new(crate_id: CrateId) -> Crate { Crate { crate_id } } - pub fn dependencies(&self, db: &impl HirDatabase) -> Vec { + pub fn dependencies(&self, db: &impl HirDatabase) -> Vec { let crate_graph = db.crate_graph(); crate_graph .dependencies(self.crate_id) - .map(|dep| Crate::new(dep.crate_id())) + .map(|dep| { + let krate = Crate::new(dep.crate_id()); + let name = dep.name.clone(); + CrateDependency { krate, name } + }) .collect() } pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable> {