diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index b9cd81739..d67ffa9de 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -21,7 +21,7 @@ use super::{ | |||
21 | 21 | ||
22 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] | 22 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] |
23 | pub(crate) struct Submodule { | 23 | pub(crate) struct Submodule { |
24 | name: SmolStr | 24 | name: SmolStr, |
25 | } | 25 | } |
26 | 26 | ||
27 | pub(crate) fn submodules( | 27 | pub(crate) fn submodules( |
@@ -29,26 +29,36 @@ pub(crate) fn submodules( | |||
29 | source: ModuleSource, | 29 | source: ModuleSource, |
30 | ) -> Cancelable<Arc<Vec<Submodule>>> { | 30 | ) -> Cancelable<Arc<Vec<Submodule>>> { |
31 | db::check_canceled(db)?; | 31 | db::check_canceled(db)?; |
32 | let file_id = match source { | 32 | let submodules = match source.resolve(db) { |
33 | ModuleSource::File(it) => it, | 33 | ModuleSourceNode::Root(it) => collect_submodules(it.ast()), |
34 | _ => unimplemented!(), | 34 | ModuleSourceNode::Inline(it) => it |
35 | .ast() | ||
36 | .item_list() | ||
37 | .map(collect_submodules) | ||
38 | .unwrap_or_else(Vec::new), | ||
35 | }; | 39 | }; |
36 | let file = db.file_syntax(file_id); | 40 | return Ok(Arc::new(submodules)); |
37 | let root = file.ast(); | 41 | |
38 | let submodules = modules(root) | 42 | fn collect_submodules<'a>(root: impl ast::ModuleItemOwner<'a>) -> Vec<Submodule> { |
39 | .map(|(name, _)| Submodule { name }) | 43 | modules(root) |
40 | .collect(); | 44 | .filter(|(_, m)| m.has_semi()) |
41 | Ok(Arc::new(submodules)) | 45 | .map(|(name, _)| Submodule { name }) |
46 | .collect() | ||
47 | } | ||
42 | } | 48 | } |
43 | 49 | ||
44 | pub(crate) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { | 50 | pub(crate) fn modules<'a>( |
45 | root.modules().filter_map(|module| { | 51 | root: impl ast::ModuleItemOwner<'a>, |
46 | let name = module.name()?.text(); | 52 | ) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> { |
47 | if !module.has_semi() { | 53 | root.items() |
48 | return None; | 54 | .filter_map(|item| match item { |
49 | } | 55 | ast::ModuleItem::Module(m) => Some(m), |
50 | Some((name, module)) | 56 | _ => None, |
51 | }) | 57 | }) |
58 | .filter_map(|module| { | ||
59 | let name = module.name()?.text(); | ||
60 | Some((name, module)) | ||
61 | }) | ||
52 | } | 62 | } |
53 | 63 | ||
54 | pub(crate) fn module_scope( | 64 | pub(crate) fn module_scope( |