aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src/input.rs')
-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 {