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)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Dependency { pub struct Dependency {
crate_id: CrateId, pub crate_id: CrateId,
name: SmolStr, pub name: SmolStr,
} }
impl Dependency { impl Dependency {

View file

@ -1,7 +1,8 @@
use crate::{HirDatabase, Module, Cancelable}; use ra_syntax::SmolStr;
pub use ra_db::CrateId; pub use ra_db::CrateId;
use crate::{HirDatabase, Module, Cancelable};
/// hir::Crate describes a single crate. It's the main inteface with which /// 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 /// crate's dependencies interact. Mostly, it should be just a proxy for the
/// root module. /// root module.
@ -10,15 +11,25 @@ pub struct Crate {
crate_id: CrateId, crate_id: CrateId,
} }
#[derive(Debug)]
pub struct CrateDependency {
pub krate: Crate,
pub name: SmolStr,
}
impl Crate { impl Crate {
pub(crate) fn new(crate_id: CrateId) -> Crate { pub(crate) fn new(crate_id: CrateId) -> Crate {
Crate { crate_id } 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(); let crate_graph = db.crate_graph();
crate_graph crate_graph
.dependencies(self.crate_id) .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() .collect()
} }
pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {