aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/Cargo.toml2
-rw-r--r--crates/ra_hir_def/src/data.rs41
-rw-r--r--crates/ra_hir_def/src/find_path.rs2
-rw-r--r--crates/ra_hir_def/src/lang_item.rs5
-rw-r--r--crates/ra_hir_def/src/nameres.rs6
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs9
6 files changed, 39 insertions, 26 deletions
diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml
index fa25cc4fb..30a12337e 100644
--- a/crates/ra_hir_def/Cargo.toml
+++ b/crates/ra_hir_def/Cargo.toml
@@ -26,4 +26,4 @@ ra_cfg = { path = "../ra_cfg" }
26tt = { path = "../ra_tt", package = "ra_tt" } 26tt = { path = "../ra_tt", package = "ra_tt" }
27 27
28[dev-dependencies] 28[dev-dependencies]
29insta = "0.13.1" 29insta = "0.15.0"
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 9fc43f3fb..a72eb5369 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -7,13 +7,16 @@ use hir_expand::{
7 AstId, InFile, 7 AstId, InFile,
8}; 8};
9use ra_prof::profile; 9use ra_prof::profile;
10use ra_syntax::ast::{self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner}; 10use ra_syntax::ast::{
11 self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner,
12};
11 13
12use crate::{ 14use crate::{
13 db::DefDatabase, 15 db::DefDatabase,
14 path::{path, GenericArgs, Path}, 16 path::{path, GenericArgs, Path},
15 src::HasSource, 17 src::HasSource,
16 type_ref::{Mutability, TypeBound, TypeRef}, 18 type_ref::{Mutability, TypeBound, TypeRef},
19 visibility::RawVisibility,
17 AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, 20 AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule,
18 ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, 21 ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
19}; 22};
@@ -26,6 +29,7 @@ pub struct FunctionData {
26 /// True if the first param is `self`. This is relevant to decide whether this 29 /// True if the first param is `self`. This is relevant to decide whether this
27 /// can be called as a method. 30 /// can be called as a method.
28 pub has_self_param: bool, 31 pub has_self_param: bool,
32 pub visibility: RawVisibility,
29} 33}
30 34
31impl FunctionData { 35impl FunctionData {
@@ -72,7 +76,9 @@ impl FunctionData {
72 ret_type 76 ret_type
73 }; 77 };
74 78
75 let sig = FunctionData { name, params, ret_type, has_self_param }; 79 let visibility = RawVisibility::from_ast(db, src.map(|s| s.visibility()));
80
81 let sig = FunctionData { name, params, ret_type, has_self_param, visibility };
76 Arc::new(sig) 82 Arc::new(sig)
77 } 83 }
78} 84}
@@ -91,6 +97,7 @@ fn desugar_future_path(orig: TypeRef) -> Path {
91pub struct TypeAliasData { 97pub struct TypeAliasData {
92 pub name: Name, 98 pub name: Name,
93 pub type_ref: Option<TypeRef>, 99 pub type_ref: Option<TypeRef>,
100 pub visibility: RawVisibility,
94} 101}
95 102
96impl TypeAliasData { 103impl TypeAliasData {
@@ -98,10 +105,11 @@ impl TypeAliasData {
98 db: &impl DefDatabase, 105 db: &impl DefDatabase,
99 typ: TypeAliasId, 106 typ: TypeAliasId,
100 ) -> Arc<TypeAliasData> { 107 ) -> Arc<TypeAliasData> {
101 let node = typ.lookup(db).source(db).value; 108 let node = typ.lookup(db).source(db);
102 let name = node.name().map_or_else(Name::missing, |n| n.as_name()); 109 let name = node.value.name().map_or_else(Name::missing, |n| n.as_name());
103 let type_ref = node.type_ref().map(TypeRef::from_ast); 110 let type_ref = node.value.type_ref().map(TypeRef::from_ast);
104 Arc::new(TypeAliasData { name, type_ref }) 111 let visibility = RawVisibility::from_ast(db, node.map(|n| n.visibility()));
112 Arc::new(TypeAliasData { name, type_ref, visibility })
105 } 113 }
106} 114}
107 115
@@ -217,23 +225,28 @@ pub struct ConstData {
217 /// const _: () = (); 225 /// const _: () = ();
218 pub name: Option<Name>, 226 pub name: Option<Name>,
219 pub type_ref: TypeRef, 227 pub type_ref: TypeRef,
228 pub visibility: RawVisibility,
220} 229}
221 230
222impl ConstData { 231impl ConstData {
223 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> { 232 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> {
224 let node = konst.lookup(db).source(db).value; 233 let node = konst.lookup(db).source(db);
225 Arc::new(ConstData::new(&node)) 234 Arc::new(ConstData::new(db, node))
226 } 235 }
227 236
228 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { 237 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> {
229 let node = konst.lookup(db).source(db).value; 238 let node = konst.lookup(db).source(db);
230 Arc::new(ConstData::new(&node)) 239 Arc::new(ConstData::new(db, node))
231 } 240 }
232 241
233 fn new<N: NameOwner + TypeAscriptionOwner>(node: &N) -> ConstData { 242 fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>(
234 let name = node.name().map(|n| n.as_name()); 243 db: &impl DefDatabase,
235 let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); 244 node: InFile<N>,
236 ConstData { name, type_ref } 245 ) -> ConstData {
246 let name = node.value.name().map(|n| n.as_name());
247 let type_ref = TypeRef::from_ast_opt(node.value.ascribed_type());
248 let visibility = RawVisibility::from_ast(db, node.map(|n| n.visibility()));
249 ConstData { name, type_ref, visibility }
237 } 250 }
238} 251}
239 252
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 43b9b124a..07ca74ec3 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -176,7 +176,7 @@ fn find_importable_locations(
176 // directly (only through reexports in direct dependencies). 176 // directly (only through reexports in direct dependencies).
177 for krate in Some(from.krate) 177 for krate in Some(from.krate)
178 .into_iter() 178 .into_iter()
179 .chain(crate_graph.dependencies(from.krate).map(|dep| dep.crate_id)) 179 .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id))
180 { 180 {
181 result.extend( 181 result.extend(
182 importable_locations_in_crate(db, item, krate) 182 importable_locations_in_crate(db, item, krate)
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index 5a336ea1f..6de49730e 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -116,8 +116,9 @@ impl LangItems {
116 if let Some(target) = start_crate_target { 116 if let Some(target) = start_crate_target {
117 return Some(*target); 117 return Some(*target);
118 } 118 }
119 db.crate_graph() 119 db.crate_graph()[start_crate]
120 .dependencies(start_crate) 120 .dependencies
121 .iter()
121 .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) 122 .find_map(|dep| db.lang_item(dep.crate_id, item.clone()))
122 } 123 }
123 124
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 628c44c99..81eac52ad 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -177,10 +177,10 @@ pub struct ModuleData {
177 177
178impl CrateDefMap { 178impl CrateDefMap {
179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
180 let _p = profile("crate_def_map_query"); 180 let _p = profile("crate_def_map_query")
181 .detail(|| db.crate_graph()[krate].display_name.clone().unwrap_or_default());
181 let def_map = { 182 let def_map = {
182 let crate_graph = db.crate_graph(); 183 let edition = db.crate_graph()[krate].edition;
183 let edition = crate_graph.edition(krate);
184 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 184 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
185 let root = modules.alloc(ModuleData::default()); 185 let root = modules.alloc(ModuleData::default());
186 CrateDefMap { 186 CrateDefMap {
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 51c65a5d7..d0459d9b0 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -34,7 +34,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
34 let crate_graph = db.crate_graph(); 34 let crate_graph = db.crate_graph();
35 35
36 // populate external prelude 36 // populate external prelude
37 for dep in crate_graph.dependencies(def_map.krate) { 37 for dep in &crate_graph[def_map.krate].dependencies {
38 let dep_def_map = db.crate_def_map(dep.crate_id); 38 let dep_def_map = db.crate_def_map(dep.crate_id);
39 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); 39 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
40 def_map.extern_prelude.insert( 40 def_map.extern_prelude.insert(
@@ -51,7 +51,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
51 } 51 }
52 } 52 }
53 53
54 let cfg_options = crate_graph.cfg_options(def_map.krate); 54 let cfg_options = &crate_graph[def_map.krate].cfg_options;
55 55
56 let mut collector = DefCollector { 56 let mut collector = DefCollector {
57 db, 57 db,
@@ -128,8 +128,7 @@ where
128 DB: DefDatabase, 128 DB: DefDatabase,
129{ 129{
130 fn collect(&mut self) { 130 fn collect(&mut self) {
131 let crate_graph = self.db.crate_graph(); 131 let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id;
132 let file_id = crate_graph.crate_root(self.def_map.krate);
133 let raw_items = self.db.raw_items(file_id.into()); 132 let raw_items = self.db.raw_items(file_id.into());
134 let module_id = self.def_map.root; 133 let module_id = self.def_map.root;
135 self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; 134 self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id };
@@ -955,7 +954,7 @@ mod tests {
955 let krate = db.test_crate(); 954 let krate = db.test_crate();
956 955
957 let def_map = { 956 let def_map = {
958 let edition = db.crate_graph().edition(krate); 957 let edition = db.crate_graph()[krate].edition;
959 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 958 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
960 let root = modules.alloc(ModuleData::default()); 959 let root = modules.alloc(ModuleData::default());
961 CrateDefMap { 960 CrateDefMap {