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.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 614325a0f..405634fe0 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -91,6 +91,7 @@ impl CrateGraph {
91 assert!(prev.is_none()); 91 assert!(prev.is_none());
92 crate_id 92 crate_id
93 } 93 }
94
94 pub fn add_dep( 95 pub fn add_dep(
95 &mut self, 96 &mut self,
96 from: CrateId, 97 from: CrateId,
@@ -102,22 +103,40 @@ impl CrateGraph {
102 } 103 }
103 Ok(self.arena.get_mut(&from).unwrap().add_dep(name, to)) 104 Ok(self.arena.get_mut(&from).unwrap().add_dep(name, to))
104 } 105 }
106
105 pub fn is_empty(&self) -> bool { 107 pub fn is_empty(&self) -> bool {
106 self.arena.is_empty() 108 self.arena.is_empty()
107 } 109 }
110
108 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 111 pub fn crate_root(&self, crate_id: CrateId) -> FileId {
109 self.arena[&crate_id].file_id 112 self.arena[&crate_id].file_id
110 } 113 }
114
111 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { 115 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
112 let (&crate_id, _) = self.arena.iter().find(|(_crate_id, data)| data.file_id == file_id)?; 116 let (&crate_id, _) = self.arena.iter().find(|(_crate_id, data)| data.file_id == file_id)?;
113 Some(crate_id) 117 Some(crate_id)
114 } 118 }
119
115 pub fn dependencies<'a>( 120 pub fn dependencies<'a>(
116 &'a self, 121 &'a self,
117 crate_id: CrateId, 122 crate_id: CrateId,
118 ) -> impl Iterator<Item = &'a Dependency> + 'a { 123 ) -> impl Iterator<Item = &'a Dependency> + 'a {
119 self.arena[&crate_id].dependencies.iter() 124 self.arena[&crate_id].dependencies.iter()
120 } 125 }
126
127 /// Extends this crate graph by adding a complete disjoint second crate
128 /// graph.
129 pub fn extend(&mut self, other: CrateGraph) {
130 let start = self.arena.len() as u32;
131 self.arena.extend(other.arena.into_iter().map(|(id, mut data)| {
132 let new_id = CrateId(id.0 + start);
133 for dep in &mut data.dependencies {
134 dep.crate_id = CrateId(dep.crate_id.0 + start);
135 }
136 (new_id, data)
137 }));
138 }
139
121 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool { 140 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool {
122 if !visited.insert(from) { 141 if !visited.insert(from) {
123 return false; 142 return false;