aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-08 07:48:45 +0100
committerAleksey Kladov <[email protected]>2019-09-09 10:32:16 +0100
commitef2b84ddf119c950272c5f1eb321f3f9e90bedd4 (patch)
treed746c95cef14b27f67f1e5fd32d289e6d20b4d57 /crates/ra_project_model
parent734a43e95afc97773c234956a95b78caed88f2a3 (diff)
introduce hir debugging infra
This is to make debugging rust-analyzer easier. The idea is that `dbg!(krate.debug(db))` will print the actual, fuzzy crate name, instead of precise ID. Debug printing infra is a separate thing, to make sure that the actual hir doesn't have access to global information. Do not use `.debug` for `log::` logging: debugging executes queries, and might introduce unneded dependencies to the crate graph
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs20
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
12use ra_db::{CrateGraph, Edition, FileId}; 12use ra_db::{CrateGraph, CrateId, Edition, FileId};
13use rustc_hash::FxHashMap; 13use rustc_hash::FxHashMap;
14use serde_json::from_reader; 14use 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> {