aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs35
1 files changed, 14 insertions, 21 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 8dbc0d667..4cd28eb4e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -12,8 +12,8 @@ use hir_def::{
12 resolver::HasResolver, 12 resolver::HasResolver,
13 type_ref::{Mutability, TypeRef}, 13 type_ref::{Mutability, TypeRef},
14 AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, 14 AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId,
15 LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, 15 LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
16 TraitId, TypeAliasId, TypeParamId, UnionId, 16 TypeParamId, UnionId,
17}; 17};
18use hir_expand::{ 18use hir_expand::{
19 diagnostics::DiagnosticSink, 19 diagnostics::DiagnosticSink,
@@ -180,13 +180,11 @@ impl Module {
180 } 180 }
181 181
182 /// Returns a `ModuleScope`: a set of items, visible in this module. 182 /// Returns a `ModuleScope`: a set of items, visible in this module.
183 pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { 183 pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef)> {
184 db.crate_def_map(self.id.krate)[self.id.local_id] 184 db.crate_def_map(self.id.krate)[self.id.local_id]
185 .scope 185 .scope
186 .entries() 186 .entries()
187 .map(|(name, res)| { 187 .map(|(name, res)| (name.clone(), res.def.into()))
188 (name.clone(), res.def.into(), res.import.map(|id| Import { parent: self, id }))
189 })
190 .collect() 188 .collect()
191 } 189 }
192 190
@@ -221,7 +219,7 @@ impl Module {
221 219
222 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { 220 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
223 let def_map = db.crate_def_map(self.id.krate); 221 let def_map = db.crate_def_map(self.id.krate);
224 def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect() 222 def_map[self.id.local_id].scope.impls().map(ImplBlock::from).collect()
225 } 223 }
226 224
227 pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module { 225 pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module {
@@ -229,11 +227,6 @@ impl Module {
229 } 227 }
230} 228}
231 229
232pub struct Import {
233 pub(crate) parent: Module,
234 pub(crate) id: LocalImportId,
235}
236
237#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 230#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
238pub struct StructField { 231pub struct StructField {
239 pub(crate) parent: VariantDef, 232 pub(crate) parent: VariantDef,
@@ -269,7 +262,7 @@ pub struct Struct {
269 262
270impl Struct { 263impl Struct {
271 pub fn module(self, db: &impl DefDatabase) -> Module { 264 pub fn module(self, db: &impl DefDatabase) -> Module {
272 Module { id: self.id.lookup(db).container } 265 Module { id: self.id.lookup(db).container.module(db) }
273 } 266 }
274 267
275 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 268 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -290,7 +283,7 @@ impl Struct {
290 } 283 }
291 284
292 pub fn ty(self, db: &impl HirDatabase) -> Type { 285 pub fn ty(self, db: &impl HirDatabase) -> Type {
293 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 286 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
294 } 287 }
295 288
296 fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { 289 fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
@@ -309,11 +302,11 @@ impl Union {
309 } 302 }
310 303
311 pub fn module(self, db: &impl DefDatabase) -> Module { 304 pub fn module(self, db: &impl DefDatabase) -> Module {
312 Module { id: self.id.lookup(db).container } 305 Module { id: self.id.lookup(db).container.module(db) }
313 } 306 }
314 307
315 pub fn ty(self, db: &impl HirDatabase) -> Type { 308 pub fn ty(self, db: &impl HirDatabase) -> Type {
316 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 309 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
317 } 310 }
318 311
319 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { 312 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
@@ -337,7 +330,7 @@ pub struct Enum {
337 330
338impl Enum { 331impl Enum {
339 pub fn module(self, db: &impl DefDatabase) -> Module { 332 pub fn module(self, db: &impl DefDatabase) -> Module {
340 Module { id: self.id.lookup(db).container } 333 Module { id: self.id.lookup(db).container.module(db) }
341 } 334 }
342 335
343 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 336 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -357,7 +350,7 @@ impl Enum {
357 } 350 }
358 351
359 pub fn ty(self, db: &impl HirDatabase) -> Type { 352 pub fn ty(self, db: &impl HirDatabase) -> Type {
360 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 353 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
361 } 354 }
362} 355}
363 356
@@ -553,7 +546,7 @@ pub struct Trait {
553 546
554impl Trait { 547impl Trait {
555 pub fn module(self, db: &impl DefDatabase) -> Module { 548 pub fn module(self, db: &impl DefDatabase) -> Module {
556 Module { id: self.id.lookup(db).container } 549 Module { id: self.id.lookup(db).container.module(db) }
557 } 550 }
558 551
559 pub fn name(self, db: &impl DefDatabase) -> Name { 552 pub fn name(self, db: &impl DefDatabase) -> Name {
@@ -754,7 +747,7 @@ impl ImplBlock {
754 let environment = TraitEnvironment::lower(db, &resolver); 747 let environment = TraitEnvironment::lower(db, &resolver);
755 let ty = Ty::from_hir(db, &resolver, &impl_data.target_type); 748 let ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
756 Type { 749 Type {
757 krate: self.id.lookup(db).container.krate, 750 krate: self.id.lookup(db).container.module(db).krate,
758 ty: InEnvironment { value: ty, environment }, 751 ty: InEnvironment { value: ty, environment },
759 } 752 }
760 } 753 }
@@ -768,7 +761,7 @@ impl ImplBlock {
768 } 761 }
769 762
770 pub fn module(&self, db: &impl DefDatabase) -> Module { 763 pub fn module(&self, db: &impl DefDatabase) -> Module {
771 self.id.lookup(db).container.into() 764 self.id.lookup(db).container.module(db).into()
772 } 765 }
773 766
774 pub fn krate(&self, db: &impl DefDatabase) -> Crate { 767 pub fn krate(&self, db: &impl DefDatabase) -> Crate {