aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/krate.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/krate.rs')
-rw-r--r--crates/ra_hir/src/krate.rs19
1 files changed, 15 insertions, 4 deletions
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>> {