mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
return dependencies with names
This commit is contained in:
parent
961cae7e53
commit
74fe581061
2 changed files with 17 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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>> {
|
||||
|
|
Loading…
Reference in a new issue