thread info about dep names

This commit is contained in:
Aleksey Kladov 2018-12-09 01:02:53 +03:00
parent ca7e5905c1
commit 961cae7e53
3 changed files with 24 additions and 12 deletions

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use rustc_hash::FxHashMap;
use rustc_hash::FxHashSet;
use rustc_hash::{FxHashSet, FxHashMap};
use ra_syntax::SmolStr;
use salsa;
use crate::file_resolver::FileResolverImp;
@ -31,14 +31,15 @@ fn new(file_id: FileId) -> CrateData {
}
}
fn add_dep(&mut self, dep: CrateId) {
self.dependencies.push(Dependency { crate_id: dep })
fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
self.dependencies.push(Dependency { name, crate_id })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Dependency {
crate_id: CrateId,
name: SmolStr,
}
impl Dependency {
@ -57,8 +58,8 @@ pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId {
//FIXME: check that we don't have cycles here.
// Just a simple depth first search from `to` should work,
// the graph is small.
pub fn add_dep(&mut self, from: CrateId, to: CrateId) {
self.arena.get_mut(&from).unwrap().add_dep(to)
pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) {
self.arena.get_mut(&from).unwrap().add_dep(name, to)
}
pub fn crate_root(&self, crate_id: CrateId) -> FileId {
self.arena[&crate_id].file_id

View File

@ -34,7 +34,13 @@ struct PackageData {
manifest: PathBuf,
targets: Vec<Target>,
is_member: bool,
dependencies: Vec<Package>,
dependencies: Vec<PackageDependency>,
}
#[derive(Debug, Clone)]
pub struct PackageDependency {
pub pkg: Package,
pub name: SmolStr,
}
#[derive(Debug, Clone)]
@ -68,8 +74,11 @@ pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target>
pub fn is_member(self, ws: &CargoWorkspace) -> bool {
ws.pkg(self).is_member
}
pub fn dependencies<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Package> + 'a {
ws.pkg(self).dependencies.iter().cloned()
pub fn dependencies<'a>(
self,
ws: &'a CargoWorkspace,
) -> impl Iterator<Item = &'a PackageDependency> + 'a {
ws.pkg(self).dependencies.iter()
}
}
@ -135,7 +144,9 @@ pub fn from_cargo_metadata(path: &Path) -> Result<CargoWorkspace> {
let source = pkg_by_id[&node.id];
for id in node.dependencies {
let target = pkg_by_id[&id];
packages[source.0].dependencies.push(target);
let name: SmolStr = packages[target.0].name.replace('-', "_").into();
let dep = PackageDependency { name, pkg: target };
packages[source.0].dependencies.push(dep);
}
}

View File

@ -162,9 +162,9 @@ pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {
}
for pkg in ws.packages() {
for dep in pkg.dependencies(ws) {
if let Some(&to) = pkg_to_lib_crate.get(&dep) {
if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
crate_graph.add_dep(from, to);
crate_graph.add_dep(from, dep.name.clone(), to);
}
}
}