aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/find_path.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-05-20 22:51:20 +0100
committerJonas Schievink <[email protected]>2020-06-04 18:33:01 +0100
commitd08c63cb9e3574fa97374a8529136814530bf416 (patch)
tree385c05e8531fccb567ca7ca688de761f4a08edb3 /crates/ra_hir_def/src/find_path.rs
parentc19496f845a4adcd7e0f48f5dcb5b405bbc63dfc (diff)
Add an ImportMap
Diffstat (limited to 'crates/ra_hir_def/src/find_path.rs')
-rw-r--r--crates/ra_hir_def/src/find_path.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 4db798473..088e8dd32 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -36,17 +36,6 @@ impl ModPath {
36 let first_segment = self.segments.first(); 36 let first_segment = self.segments.first();
37 first_segment == Some(&known::alloc) || first_segment == Some(&known::core) 37 first_segment == Some(&known::alloc) || first_segment == Some(&known::core)
38 } 38 }
39
40 fn len(&self) -> usize {
41 self.segments.len()
42 + match self.kind {
43 PathKind::Plain => 0,
44 PathKind::Super(i) => i as usize,
45 PathKind::Crate => 1,
46 PathKind::Abs => 0,
47 PathKind::DollarCrate(_) => 1,
48 }
49 }
50} 39}
51 40
52pub(crate) fn find_path_inner_query( 41pub(crate) fn find_path_inner_query(
@@ -192,9 +181,17 @@ fn find_importable_locations(
192) -> Vec<(ModuleId, Name)> { 181) -> Vec<(ModuleId, Name)> {
193 let crate_graph = db.crate_graph(); 182 let crate_graph = db.crate_graph();
194 let mut result = Vec::new(); 183 let mut result = Vec::new();
184
195 // We only look in the crate from which we are importing, and the direct 185 // We only look in the crate from which we are importing, and the direct
196 // dependencies. We cannot refer to names from transitive dependencies 186 // dependencies. We cannot refer to names from transitive dependencies
197 // directly (only through reexports in direct dependencies). 187 // directly (only through reexports in direct dependencies).
188
189 // For the crate from which we're importing, we have to check whether any
190 // module visible to `from` exports the item we're looking for.
191 // For dependencies of the crate only `pub` items reachable through `pub`
192 // modules from the crate root are relevant. For that we precompute an
193 // import map that tells us the shortest path to any importable item with a
194 // single lookup.
198 for krate in Some(from.krate) 195 for krate in Some(from.krate)
199 .into_iter() 196 .into_iter()
200 .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id)) 197 .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id))