diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-01 10:53:17 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-01 10:53:17 +0000 |
commit | f6f9a0bf35f073e554a340f04e213867732d81a1 (patch) | |
tree | 9c9cfc3f6868864d7dd1164aaff6b248f81a402b /crates/ra_analysis/src/descriptors/module/imp.rs | |
parent | d685a9b564fe524865cda5713c527aaeb1ca6b1d (diff) | |
parent | f2b654fd443ce1a0a31a9eaf1a1c25e911d0001a (diff) |
Merge #182
182: Module source r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index 1c102f4e5..3a010ecf5 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | ast::{self, NameOwner}, | 4 | ast::{self, ModuleItemOwner, NameOwner}, |
5 | SmolStr, | 5 | SmolStr, |
6 | }; | 6 | }; |
7 | use relative_path::RelativePathBuf; | 7 | use relative_path::RelativePathBuf; |
@@ -14,7 +14,10 @@ use crate::{ | |||
14 | Cancelable, FileId, FileResolverImp, | 14 | Cancelable, FileId, FileResolverImp, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use super::{LinkData, LinkId, ModuleData, ModuleId, ModuleScope, ModuleTree, Problem}; | 17 | use super::{ |
18 | LinkData, LinkId, ModuleData, ModuleId, ModuleScope, ModuleSource, ModuleSourceNode, | ||
19 | ModuleTree, Problem, | ||
20 | }; | ||
18 | 21 | ||
19 | pub(crate) fn submodules( | 22 | pub(crate) fn submodules( |
20 | db: &impl DescriptorDatabase, | 23 | db: &impl DescriptorDatabase, |
@@ -43,9 +46,14 @@ pub(crate) fn module_scope( | |||
43 | module_id: ModuleId, | 46 | module_id: ModuleId, |
44 | ) -> Cancelable<Arc<ModuleScope>> { | 47 | ) -> Cancelable<Arc<ModuleScope>> { |
45 | let tree = db.module_tree(source_root_id)?; | 48 | let tree = db.module_tree(source_root_id)?; |
46 | let file_id = module_id.file_id(&tree); | 49 | let source = module_id.source(&tree).resolve(db); |
47 | let syntax = db.file_syntax(file_id); | 50 | let res = match source { |
48 | let res = ModuleScope::new(&syntax); | 51 | ModuleSourceNode::Root(root) => ModuleScope::new(root.ast().items()), |
52 | ModuleSourceNode::Inline(inline) => match inline.ast().item_list() { | ||
53 | Some(items) => ModuleScope::new(items.items()), | ||
54 | None => ModuleScope::new(std::iter::empty()), | ||
55 | }, | ||
56 | }; | ||
49 | Ok(Arc::new(res)) | 57 | Ok(Arc::new(res)) |
50 | } | 58 | } |
51 | 59 | ||
@@ -106,7 +114,7 @@ fn build_subtree( | |||
106 | ) -> Cancelable<ModuleId> { | 114 | ) -> Cancelable<ModuleId> { |
107 | visited.insert(file_id); | 115 | visited.insert(file_id); |
108 | let id = tree.push_mod(ModuleData { | 116 | let id = tree.push_mod(ModuleData { |
109 | file_id, | 117 | source: ModuleSource::File(file_id), |
110 | parent, | 118 | parent, |
111 | children: Vec::new(), | 119 | children: Vec::new(), |
112 | }); | 120 | }); |