aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
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_db
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_db')
-rw-r--r--crates/ra_db/src/input.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index d1ee3c036..a1ace61b6 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -82,6 +82,12 @@ pub struct CyclicDependencies;
82#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 82#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
83pub struct CrateId(pub u32); 83pub struct CrateId(pub u32);
84 84
85impl CrateId {
86 pub fn shift(self, amount: u32) -> CrateId {
87 CrateId(self.0 + amount)
88 }
89}
90
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
86pub enum Edition { 92pub enum Edition {
87 Edition2018, 93 Edition2018,
@@ -178,15 +184,19 @@ impl CrateGraph {
178 184
179 /// Extends this crate graph by adding a complete disjoint second crate 185 /// Extends this crate graph by adding a complete disjoint second crate
180 /// graph. 186 /// graph.
181 pub fn extend(&mut self, other: CrateGraph) { 187 ///
188 /// The ids of the crates in the `other` graph are shifted by the return
189 /// amount.
190 pub fn extend(&mut self, other: CrateGraph) -> u32 {
182 let start = self.arena.len() as u32; 191 let start = self.arena.len() as u32;
183 self.arena.extend(other.arena.into_iter().map(|(id, mut data)| { 192 self.arena.extend(other.arena.into_iter().map(|(id, mut data)| {
184 let new_id = CrateId(id.0 + start); 193 let new_id = id.shift(start);
185 for dep in &mut data.dependencies { 194 for dep in &mut data.dependencies {
186 dep.crate_id = CrateId(dep.crate_id.0 + start); 195 dep.crate_id = dep.crate_id.shift(start);
187 } 196 }
188 (new_id, data) 197 (new_id, data)
189 })); 198 }));
199 start
190 } 200 }
191 201
192 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool { 202 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool {