aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-05 10:08:52 +0000
committerAleksey Kladov <[email protected]>2018-11-05 10:08:52 +0000
commit17a88928f49f31b9b076ef66d57354f45032be56 (patch)
tree6325dc95d6f01928ecf8a265dc1ce60e4454b4e7 /crates/ra_analysis/src
parente0b21b98996b8296942c23864c711b2c1078178a (diff)
collect all submodules
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/descriptors/mod.rs4
-rw-r--r--crates/ra_analysis/src/descriptors/module/imp.rs46
2 files changed, 30 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs
index 775949a88..56bde3849 100644
--- a/crates/ra_analysis/src/descriptors/mod.rs
+++ b/crates/ra_analysis/src/descriptors/mod.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
5 5
6use ra_syntax::{ 6use ra_syntax::{
7 ast::{self, AstNode, FnDefNode}, 7 ast::{self, AstNode, FnDefNode},
8 SmolStr, TextRange, 8 TextRange,
9}; 9};
10 10
11use crate::{ 11use crate::{
@@ -14,7 +14,7 @@ use crate::{
14 descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, 14 descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource},
15 input::SourceRootId, 15 input::SourceRootId,
16 syntax_ptr::LocalSyntaxPtr, 16 syntax_ptr::LocalSyntaxPtr,
17 Cancelable, FileId, 17 Cancelable,
18}; 18};
19 19
20salsa::query_group! { 20salsa::query_group! {
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)]
23pub(crate) struct Submodule { 23pub(crate) struct Submodule {
24 name: SmolStr 24 name: SmolStr,
25} 25}
26 26
27pub(crate) fn submodules( 27pub(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
44pub(crate) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { 50pub(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
54pub(crate) fn module_scope( 64pub(crate) fn module_scope(