diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/find_path.rs | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e665ab45d..498a4c917 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Defines database & queries for name resolution. | 1 | //! Defines database & queries for name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_expand::{db::AstDatabase, HirFileId}; | 4 | use hir_expand::{db::AstDatabase, name::Name, HirFileId}; |
5 | use ra_db::{salsa, CrateId, SourceDatabase, Upcast}; | 5 | use ra_db::{salsa, CrateId, SourceDatabase, Upcast}; |
6 | use ra_prof::profile; | 6 | use ra_prof::profile; |
7 | use ra_syntax::SmolStr; | 7 | use ra_syntax::SmolStr; |
@@ -12,9 +12,12 @@ use crate::{ | |||
12 | body::{scope::ExprScopes, Body, BodySourceMap}, | 12 | body::{scope::ExprScopes, Body, BodySourceMap}, |
13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, | 13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, |
14 | docs::Documentation, | 14 | docs::Documentation, |
15 | find_path, | ||
15 | generics::GenericParams, | 16 | generics::GenericParams, |
17 | item_scope::ItemInNs, | ||
16 | lang_item::{LangItemTarget, LangItems}, | 18 | lang_item::{LangItemTarget, LangItems}, |
17 | nameres::{raw::RawItems, CrateDefMap}, | 19 | nameres::{raw::RawItems, CrateDefMap}, |
20 | visibility::Visibility, | ||
18 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, | 21 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, |
19 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, | 22 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, |
20 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, | 23 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, |
@@ -108,6 +111,13 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | |||
108 | // Remove this query completely, in favor of `Attrs::docs` method | 111 | // Remove this query completely, in favor of `Attrs::docs` method |
109 | #[salsa::invoke(Documentation::documentation_query)] | 112 | #[salsa::invoke(Documentation::documentation_query)] |
110 | fn documentation(&self, def: AttrDefId) -> Option<Documentation>; | 113 | fn documentation(&self, def: AttrDefId) -> Option<Documentation>; |
114 | |||
115 | #[salsa::invoke(find_path::importable_locations_in_crate)] | ||
116 | fn importable_locations_of( | ||
117 | &self, | ||
118 | item: ItemInNs, | ||
119 | krate: CrateId, | ||
120 | ) -> Arc<[(ModuleId, Name, Visibility)]>; | ||
111 | } | 121 | } |
112 | 122 | ||
113 | fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { | 123 | fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { |
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 | }; |
10 | use hir_expand::name::{known, AsName, Name}; | 10 | use hir_expand::name::{known, AsName, Name}; |
11 | use std::sync::Arc; | ||
11 | use test_utils::tested_by; | 12 | use test_utils::tested_by; |
12 | 13 | ||
13 | const MAX_PATH_LEN: usize = 15; | 14 | const 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. |
47 | pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { | 48 | pub 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. |
216 | fn importable_locations_in_crate( | 218 | pub(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)] |