diff options
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 9b2f534e7..4fa32dc34 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -9,7 +9,7 @@ use std::{ | |||
9 | path::{Path, PathBuf}, | 9 | path::{Path, PathBuf}, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use ra_db::{CrateGraph, Edition, FileId}; | 12 | use ra_db::{CrateGraph, CrateId, Edition, FileId}; |
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
14 | use serde_json::from_reader; | 14 | use serde_json::from_reader; |
15 | 15 | ||
@@ -113,8 +113,12 @@ impl ProjectWorkspace { | |||
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | pub fn to_crate_graph(&self, load: &mut dyn FnMut(&Path) -> Option<FileId>) -> CrateGraph { | 116 | pub fn to_crate_graph( |
117 | &self, | ||
118 | load: &mut dyn FnMut(&Path) -> Option<FileId>, | ||
119 | ) -> (CrateGraph, FxHashMap<CrateId, String>) { | ||
117 | let mut crate_graph = CrateGraph::default(); | 120 | let mut crate_graph = CrateGraph::default(); |
121 | let mut names = FxHashMap::default(); | ||
118 | match self { | 122 | match self { |
119 | ProjectWorkspace::Json { project } => { | 123 | ProjectWorkspace::Json { project } => { |
120 | let mut crates = FxHashMap::default(); | 124 | let mut crates = FxHashMap::default(); |
@@ -151,10 +155,9 @@ impl ProjectWorkspace { | |||
151 | let mut sysroot_crates = FxHashMap::default(); | 155 | let mut sysroot_crates = FxHashMap::default(); |
152 | for krate in sysroot.crates() { | 156 | for krate in sysroot.crates() { |
153 | if let Some(file_id) = load(krate.root(&sysroot)) { | 157 | if let Some(file_id) = load(krate.root(&sysroot)) { |
154 | sysroot_crates.insert( | 158 | let crate_id = crate_graph.add_crate_root(file_id, Edition::Edition2018); |
155 | krate, | 159 | sysroot_crates.insert(krate, crate_id); |
156 | crate_graph.add_crate_root(file_id, Edition::Edition2018), | 160 | names.insert(crate_id, krate.name(&sysroot).to_string()); |
157 | ); | ||
158 | } | 161 | } |
159 | } | 162 | } |
160 | for from in sysroot.crates() { | 163 | for from in sysroot.crates() { |
@@ -182,6 +185,7 @@ impl ProjectWorkspace { | |||
182 | if let Some(file_id) = load(root) { | 185 | if let Some(file_id) = load(root) { |
183 | let edition = pkg.edition(&cargo); | 186 | let edition = pkg.edition(&cargo); |
184 | let crate_id = crate_graph.add_crate_root(file_id, edition); | 187 | let crate_id = crate_graph.add_crate_root(file_id, edition); |
188 | names.insert(crate_id, pkg.name(&cargo).to_string()); | ||
185 | if tgt.kind(&cargo) == TargetKind::Lib { | 189 | if tgt.kind(&cargo) == TargetKind::Lib { |
186 | lib_tgt = Some(crate_id); | 190 | lib_tgt = Some(crate_id); |
187 | pkg_to_lib_crate.insert(pkg, crate_id); | 191 | pkg_to_lib_crate.insert(pkg, crate_id); |
@@ -212,7 +216,7 @@ impl ProjectWorkspace { | |||
212 | } | 216 | } |
213 | } | 217 | } |
214 | 218 | ||
215 | // Now add a dep ednge from all targets of upstream to the lib | 219 | // Now add a dep edge from all targets of upstream to the lib |
216 | // target of downstream. | 220 | // target of downstream. |
217 | for pkg in cargo.packages() { | 221 | for pkg in cargo.packages() { |
218 | for dep in pkg.dependencies(&cargo) { | 222 | for dep in pkg.dependencies(&cargo) { |
@@ -233,7 +237,7 @@ impl ProjectWorkspace { | |||
233 | } | 237 | } |
234 | } | 238 | } |
235 | } | 239 | } |
236 | crate_graph | 240 | (crate_graph, names) |
237 | } | 241 | } |
238 | 242 | ||
239 | pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { | 243 | pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { |