diff options
-rw-r--r-- | crates/ra_analysis/src/descriptors/mod.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 46 |
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 | ||
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, AstNode, FnDefNode}, | 7 | ast::{self, AstNode, FnDefNode}, |
8 | SmolStr, TextRange, | 8 | TextRange, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use 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 | ||
20 | salsa::query_group! { | 20 | salsa::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)] |
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( |