diff options
author | Aleksey Kladov <[email protected]> | 2020-01-16 16:52:58 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-16 16:52:58 +0000 |
commit | 6bc236253dd9cd8e0729bbb681f0e03b20bc3627 (patch) | |
tree | 4b07ef6bdf3b8173a9456f8659cfeabb83772a78 /crates/ra_hir/src | |
parent | 595b06a1b8fcd215c828d65ee1dd1a30c2697de9 (diff) |
Correctly discover module containers
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index fa225a4ed..b2b17d510 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -111,7 +111,10 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> { | |||
111 | let def: UnionId = self.to_id(container.with_value(it))?; | 111 | let def: UnionId = self.to_id(container.with_value(it))?; |
112 | VariantId::from(def).into() | 112 | VariantId::from(def).into() |
113 | }, | 113 | }, |
114 | // FIXME: handle out-of-line modules here | 114 | ast::Module(it) => { |
115 | let def: ModuleId = self.to_id(container.with_value(it))?; | ||
116 | def.into() | ||
117 | }, | ||
115 | _ => { continue }, | 118 | _ => { continue }, |
116 | } | 119 | } |
117 | }; | 120 | }; |
@@ -162,6 +165,7 @@ macro_rules! to_def_impls { | |||
162 | } | 165 | } |
163 | 166 | ||
164 | to_def_impls![ | 167 | to_def_impls![ |
168 | (crate::Module, ast::Module), | ||
165 | (crate::Struct, ast::StructDef), | 169 | (crate::Struct, ast::StructDef), |
166 | (crate::Enum, ast::EnumDef), | 170 | (crate::Enum, ast::EnumDef), |
167 | (crate::Union, ast::UnionDef), | 171 | (crate::Union, ast::UnionDef), |
@@ -318,13 +322,13 @@ impl ToDef for ast::TypeParam { | |||
318 | } | 322 | } |
319 | } | 323 | } |
320 | 324 | ||
321 | impl ToDef for ast::Module { | 325 | impl ToId for ast::Module { |
322 | type Def = Module; | 326 | type ID = ModuleId; |
323 | 327 | ||
324 | fn to_def<DB: HirDatabase>( | 328 | fn to_id<DB: HirDatabase>( |
325 | sb: &mut SourceBinder<'_, DB>, | 329 | sb: &mut SourceBinder<'_, DB>, |
326 | src: InFile<ast::Module>, | 330 | src: InFile<ast::Module>, |
327 | ) -> Option<Module> { | 331 | ) -> Option<ModuleId> { |
328 | { | 332 | { |
329 | let _p = profile("ast::Module::to_def"); | 333 | let _p = profile("ast::Module::to_def"); |
330 | let parent_declaration = src | 334 | let parent_declaration = src |
@@ -339,17 +343,17 @@ impl ToDef for ast::Module { | |||
339 | }); | 343 | }); |
340 | 344 | ||
341 | let parent_module = match parent_declaration { | 345 | let parent_module = match parent_declaration { |
342 | Some(parent_declaration) => sb.to_def(parent_declaration), | 346 | Some(parent_declaration) => sb.to_id(parent_declaration)?, |
343 | None => { | 347 | None => { |
344 | let file_id = src.file_id.original_file(sb.db); | 348 | let file_id = src.file_id.original_file(sb.db); |
345 | sb.to_module_def(file_id) | 349 | sb.to_module_def(file_id)?.id |
346 | } | 350 | } |
347 | }?; | 351 | }; |
348 | 352 | ||
349 | let child_name = src.value.name()?.as_name(); | 353 | let child_name = src.value.name()?.as_name(); |
350 | let def_map = sb.db.crate_def_map(parent_module.id.krate); | 354 | let def_map = sb.db.crate_def_map(parent_module.krate); |
351 | let child_id = def_map[parent_module.id.local_id].children.get(&child_name)?; | 355 | let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; |
352 | Some(parent_module.with_module_id(*child_id)) | 356 | Some(ModuleId { krate: parent_module.krate, local_id: child_id }) |
353 | } | 357 | } |
354 | } | 358 | } |
355 | } | 359 | } |