aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-08 22:02:53 +0000
committerAleksey Kladov <[email protected]>2018-12-09 10:33:16 +0000
commit961cae7e53a05625f3e010076673ca083479b481 (patch)
tree653672f36816ff6eb2bf098a06e48e7d3adbee56 /crates
parentca7e5905c1daffbed6a08fe674ae821f99bd274d (diff)
thread info about dep names
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs13
-rw-r--r--crates/ra_lsp_server/src/project_model.rs19
-rw-r--r--crates/ra_lsp_server/src/server_world.rs4
3 files changed, 24 insertions, 12 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 37da8c549..44c5bac93 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -1,7 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use rustc_hash::FxHashMap; 3use rustc_hash::{FxHashSet, FxHashMap};
4use rustc_hash::FxHashSet; 4use ra_syntax::SmolStr;
5use salsa; 5use salsa;
6 6
7use crate::file_resolver::FileResolverImp; 7use crate::file_resolver::FileResolverImp;
@@ -31,14 +31,15 @@ impl CrateData {
31 } 31 }
32 } 32 }
33 33
34 fn add_dep(&mut self, dep: CrateId) { 34 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
35 self.dependencies.push(Dependency { crate_id: dep }) 35 self.dependencies.push(Dependency { name, crate_id })
36 } 36 }
37} 37}
38 38
39#[derive(Debug, Clone, PartialEq, Eq)] 39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct Dependency { 40pub struct Dependency {
41 crate_id: CrateId, 41 crate_id: CrateId,
42 name: SmolStr,
42} 43}
43 44
44impl Dependency { 45impl Dependency {
@@ -57,8 +58,8 @@ impl CrateGraph {
57 //FIXME: check that we don't have cycles here. 58 //FIXME: check that we don't have cycles here.
58 // Just a simple depth first search from `to` should work, 59 // Just a simple depth first search from `to` should work,
59 // the graph is small. 60 // the graph is small.
60 pub fn add_dep(&mut self, from: CrateId, to: CrateId) { 61 pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) {
61 self.arena.get_mut(&from).unwrap().add_dep(to) 62 self.arena.get_mut(&from).unwrap().add_dep(name, to)
62 } 63 }
63 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 64 pub fn crate_root(&self, crate_id: CrateId) -> FileId {
64 self.arena[&crate_id].file_id 65 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 5da71b9f5..cb91ada90 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 {
34 manifest: PathBuf, 34 manifest: PathBuf,
35 targets: Vec<Target>, 35 targets: Vec<Target>,
36 is_member: bool, 36 is_member: bool,
37 dependencies: Vec<Package>, 37 dependencies: Vec<PackageDependency>,
38}
39
40#[derive(Debug, Clone)]
41pub struct PackageDependency {
42 pub pkg: Package,
43 pub name: SmolStr,
38} 44}
39 45
40#[derive(Debug, Clone)] 46#[derive(Debug, Clone)]
@@ -68,8 +74,11 @@ impl Package {
68 pub fn is_member(self, ws: &CargoWorkspace) -> bool { 74 pub fn is_member(self, ws: &CargoWorkspace) -> bool {
69 ws.pkg(self).is_member 75 ws.pkg(self).is_member
70 } 76 }
71 pub fn dependencies<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Package> + 'a { 77 pub fn dependencies<'a>(
72 ws.pkg(self).dependencies.iter().cloned() 78 self,
79 ws: &'a CargoWorkspace,
80 ) -> impl Iterator<Item = &'a PackageDependency> + 'a {
81 ws.pkg(self).dependencies.iter()
73 } 82 }
74} 83}
75 84
@@ -135,7 +144,9 @@ impl CargoWorkspace {
135 let source = pkg_by_id[&node.id]; 144 let source = pkg_by_id[&node.id];
136 for id in node.dependencies { 145 for id in node.dependencies {
137 let target = pkg_by_id[&id]; 146 let target = pkg_by_id[&id];
138 packages[source.0].dependencies.push(target); 147 let name: SmolStr = packages[target.0].name.replace('-', "_").into();
148 let dep = PackageDependency { name, pkg: target };
149 packages[source.0].dependencies.push(dep);
139 } 150 }
140 } 151 }
141 152
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index f2d602dc7..ab4c2c8aa 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -162,9 +162,9 @@ impl ServerWorldState {
162 } 162 }
163 for pkg in ws.packages() { 163 for pkg in ws.packages() {
164 for dep in pkg.dependencies(ws) { 164 for dep in pkg.dependencies(ws) {
165 if let Some(&to) = pkg_to_lib_crate.get(&dep) { 165 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
166 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 166 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
167 crate_graph.add_dep(from, to); 167 crate_graph.add_dep(from, dep.name.clone(), to);
168 } 168 }
169 } 169 }
170 } 170 }