From 961cae7e53a05625f3e010076673ca083479b481 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 01:02:53 +0300 Subject: [PATCH] thread info about dep names --- crates/ra_db/src/input.rs | 13 +++++++------ crates/ra_lsp_server/src/project_model.rs | 19 +++++++++++++++---- crates/ra_lsp_server/src/server_world.rs | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 37da8c5495a..44c5bac9328 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -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 diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 5da71b9f54f..cb91ada90ac 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs @@ -34,7 +34,13 @@ struct PackageData { manifest: PathBuf, targets: Vec, is_member: bool, - dependencies: Vec, + dependencies: Vec, +} + +#[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 pub fn is_member(self, ws: &CargoWorkspace) -> bool { ws.pkg(self).is_member } - pub fn dependencies<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator + 'a { - ws.pkg(self).dependencies.iter().cloned() + pub fn dependencies<'a>( + self, + ws: &'a CargoWorkspace, + ) -> impl Iterator + 'a { + ws.pkg(self).dependencies.iter() } } @@ -135,7 +144,9 @@ pub fn from_cargo_metadata(path: &Path) -> Result { 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); } } diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index f2d602dc785..ab4c2c8aad6 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -162,9 +162,9 @@ pub fn set_workspaces(&mut self, ws: Vec) { } 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); } } }