return dependencies with names

This commit is contained in:
Aleksey Kladov 2018-12-09 01:05:49 +03:00
parent 961cae7e53
commit 74fe581061
2 changed files with 17 additions and 6 deletions

View file

@ -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 {

View file

@ -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<Crate> {
pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
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<Option<Module>> {