diff options
author | Aleksey Kladov <[email protected]> | 2019-01-06 14:44:50 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-06 14:44:50 +0000 |
commit | 733383446fc229a35d4432d14c295c5a01e5a87f (patch) | |
tree | bffd84981df9cca1143807796dc6772ddcfe8e0b /crates/ra_hir/src/query_definitions.rs | |
parent | 17b2994b99394562b5e515c953a3a83c5977da76 (diff) |
move submodule computationt to module_tree
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index b17c00e26..f4b380022 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -6,16 +6,16 @@ use std::{ | |||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | AstNode, SyntaxNode, | 8 | AstNode, SyntaxNode, |
9 | ast::{self, NameOwner, ModuleItemOwner} | 9 | ast::{self, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, Cancelable,}; | 11 | use ra_db::{SourceRootId, Cancelable,}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefKind, DefId, Name, AsName, HirFileId, | 14 | SourceFileItems, SourceItemId, DefKind, DefId, HirFileId, |
15 | MacroCallLoc, | 15 | MacroCallLoc, |
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | function::FnScopes, | 17 | function::FnScopes, |
18 | module_tree::{ModuleId, Submodule, ModuleSource, ModuleSourceNode}, | 18 | module_tree::{ModuleId, ModuleSourceNode}, |
19 | nameres::{InputModuleItems, ItemMap, Resolver}, | 19 | nameres::{InputModuleItems, ItemMap, Resolver}, |
20 | adt::{StructData, EnumData}, | 20 | adt::{StructData, EnumData}, |
21 | }; | 21 | }; |
@@ -58,54 +58,6 @@ pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> | |||
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | pub(crate) fn submodules( | ||
62 | db: &impl HirDatabase, | ||
63 | source: ModuleSource, | ||
64 | ) -> Cancelable<Arc<Vec<Submodule>>> { | ||
65 | db.check_canceled()?; | ||
66 | let file_id = source.file_id(); | ||
67 | let submodules = match source.resolve(db) { | ||
68 | ModuleSourceNode::SourceFile(it) => collect_submodules(db, file_id, it.borrowed()), | ||
69 | ModuleSourceNode::Module(it) => it | ||
70 | .borrowed() | ||
71 | .item_list() | ||
72 | .map(|it| collect_submodules(db, file_id, it)) | ||
73 | .unwrap_or_else(Vec::new), | ||
74 | }; | ||
75 | return Ok(Arc::new(submodules)); | ||
76 | |||
77 | fn collect_submodules<'a>( | ||
78 | db: &impl HirDatabase, | ||
79 | file_id: HirFileId, | ||
80 | root: impl ast::ModuleItemOwner<'a>, | ||
81 | ) -> Vec<Submodule> { | ||
82 | modules(root) | ||
83 | .map(|(name, m)| { | ||
84 | if m.has_semi() { | ||
85 | Submodule::Declaration(name) | ||
86 | } else { | ||
87 | let src = ModuleSource::new_inline(db, file_id, m); | ||
88 | Submodule::Definition(name, src) | ||
89 | } | ||
90 | }) | ||
91 | .collect() | ||
92 | } | ||
93 | } | ||
94 | |||
95 | pub(crate) fn modules<'a>( | ||
96 | root: impl ast::ModuleItemOwner<'a>, | ||
97 | ) -> impl Iterator<Item = (Name, ast::Module<'a>)> { | ||
98 | root.items() | ||
99 | .filter_map(|item| match item { | ||
100 | ast::ModuleItem::Module(m) => Some(m), | ||
101 | _ => None, | ||
102 | }) | ||
103 | .filter_map(|module| { | ||
104 | let name = module.name()?.as_name(); | ||
105 | Some((name, module)) | ||
106 | }) | ||
107 | } | ||
108 | |||
109 | pub(super) fn input_module_items( | 61 | pub(super) fn input_module_items( |
110 | db: &impl HirDatabase, | 62 | db: &impl HirDatabase, |
111 | source_root_id: SourceRootId, | 63 | source_root_id: SourceRootId, |