aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir/module/imp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/hir/module/imp.rs')
-rw-r--r--crates/ra_analysis/src/hir/module/imp.rs35
1 files changed, 1 insertions, 34 deletions
diff --git a/crates/ra_analysis/src/hir/module/imp.rs b/crates/ra_analysis/src/hir/module/imp.rs
index f9853584e..3b1baff76 100644
--- a/crates/ra_analysis/src/hir/module/imp.rs
+++ b/crates/ra_analysis/src/hir/module/imp.rs
@@ -15,7 +15,7 @@ use crate::{
15}; 15};
16 16
17use super::{ 17use super::{
18 LinkData, LinkId, ModuleData, ModuleId, ModuleSource, ModuleSourceNode, 18 LinkData, LinkId, ModuleData, ModuleId, ModuleSource,
19 ModuleTree, Problem, 19 ModuleTree, Problem,
20}; 20};
21 21
@@ -34,39 +34,6 @@ impl Submodule {
34 } 34 }
35} 35}
36 36
37pub(crate) fn submodules(
38 db: &impl HirDatabase,
39 source: ModuleSource,
40) -> Cancelable<Arc<Vec<Submodule>>> {
41 db::check_canceled(db)?;
42 let file_id = source.file_id();
43 let submodules = match source.resolve(db) {
44 ModuleSourceNode::SourceFile(it) => collect_submodules(file_id, it.borrowed()),
45 ModuleSourceNode::Module(it) => it
46 .borrowed()
47 .item_list()
48 .map(|it| collect_submodules(file_id, it))
49 .unwrap_or_else(Vec::new),
50 };
51 return Ok(Arc::new(submodules));
52
53 fn collect_submodules<'a>(
54 file_id: FileId,
55 root: impl ast::ModuleItemOwner<'a>,
56 ) -> Vec<Submodule> {
57 modules(root)
58 .map(|(name, m)| {
59 if m.has_semi() {
60 Submodule::Declaration(name)
61 } else {
62 let src = ModuleSource::new_inline(file_id, m);
63 Submodule::Definition(name, src)
64 }
65 })
66 .collect()
67 }
68}
69
70pub(crate) fn modules<'a>( 37pub(crate) fn modules<'a>(
71 root: impl ast::ModuleItemOwner<'a>, 38 root: impl ast::ModuleItemOwner<'a>,
72) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> { 39) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> {