aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/find_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/find_path.rs')
-rw-r--r--crates/ra_hir_def/src/find_path.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 70dcb03e6..1ca20fabd 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -8,6 +8,7 @@ use crate::{
8 CrateId, ModuleDefId, ModuleId, 8 CrateId, ModuleDefId, ModuleId,
9}; 9};
10use hir_expand::name::{known, AsName, Name}; 10use hir_expand::name::{known, AsName, Name};
11use std::sync::Arc;
11use test_utils::tested_by; 12use test_utils::tested_by;
12 13
13const MAX_PATH_LEN: usize = 15; 14const MAX_PATH_LEN: usize = 15;
@@ -45,6 +46,7 @@ impl ModPath {
45/// Find a path that can be used to refer to a certain item. This can depend on 46/// Find a path that can be used to refer to a certain item. This can depend on
46/// *from where* you're referring to the item, hence the `from` parameter. 47/// *from where* you're referring to the item, hence the `from` parameter.
47pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { 48pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
49 let _p = ra_prof::profile("find_path");
48 find_path_inner(db, item, from, MAX_PATH_LEN) 50 find_path_inner(db, item, from, MAX_PATH_LEN)
49} 51}
50 52
@@ -198,7 +200,7 @@ fn find_importable_locations(
198 .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id)) 200 .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id))
199 { 201 {
200 result.extend( 202 result.extend(
201 importable_locations_in_crate(db, item, krate) 203 db.importable_locations_of(item, krate)
202 .iter() 204 .iter()
203 .filter(|(_, _, vis)| vis.is_visible_from(db, from)) 205 .filter(|(_, _, vis)| vis.is_visible_from(db, from))
204 .map(|(m, n, _)| (*m, n.clone())), 206 .map(|(m, n, _)| (*m, n.clone())),
@@ -213,11 +215,11 @@ fn find_importable_locations(
213/// 215///
214/// Note that the crate doesn't need to be the one in which the item is defined; 216/// Note that the crate doesn't need to be the one in which the item is defined;
215/// it might be re-exported in other crates. 217/// it might be re-exported in other crates.
216fn importable_locations_in_crate( 218pub(crate) fn importable_locations_in_crate(
217 db: &dyn DefDatabase, 219 db: &dyn DefDatabase,
218 item: ItemInNs, 220 item: ItemInNs,
219 krate: CrateId, 221 krate: CrateId,
220) -> Vec<(ModuleId, Name, Visibility)> { 222) -> Arc<[(ModuleId, Name, Visibility)]> {
221 let def_map = db.crate_def_map(krate); 223 let def_map = db.crate_def_map(krate);
222 let mut result = Vec::new(); 224 let mut result = Vec::new();
223 for (local_id, data) in def_map.modules.iter() { 225 for (local_id, data) in def_map.modules.iter() {
@@ -243,7 +245,8 @@ fn importable_locations_in_crate(
243 result.push((ModuleId { krate, local_id }, name.clone(), vis)); 245 result.push((ModuleId { krate, local_id }, name.clone(), vis));
244 } 246 }
245 } 247 }
246 result 248
249 Arc::from(result)
247} 250}
248 251
249#[cfg(test)] 252#[cfg(test)]