diff options
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 59 |
1 files changed, 4 insertions, 55 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index d9ee9d37f..f4b380022 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -6,20 +6,17 @@ 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::{ | 18 | module_tree::{ModuleId, ModuleSourceNode}, |
19 | ModuleSource, ModuleSourceNode, ModuleId, | 19 | nameres::{InputModuleItems, ItemMap, Resolver}, |
20 | imp::Submodule, | ||
21 | nameres::{InputModuleItems, ItemMap, Resolver}, | ||
22 | }, | ||
23 | adt::{StructData, EnumData}, | 20 | adt::{StructData, EnumData}, |
24 | }; | 21 | }; |
25 | 22 | ||
@@ -61,54 +58,6 @@ pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> | |||
61 | } | 58 | } |
62 | } | 59 | } |
63 | 60 | ||
64 | pub(crate) fn submodules( | ||
65 | db: &impl HirDatabase, | ||
66 | source: ModuleSource, | ||
67 | ) -> Cancelable<Arc<Vec<Submodule>>> { | ||
68 | db.check_canceled()?; | ||
69 | let file_id = source.file_id(); | ||
70 | let submodules = match source.resolve(db) { | ||
71 | ModuleSourceNode::SourceFile(it) => collect_submodules(db, file_id, it.borrowed()), | ||
72 | ModuleSourceNode::Module(it) => it | ||
73 | .borrowed() | ||
74 | .item_list() | ||
75 | .map(|it| collect_submodules(db, file_id, it)) | ||
76 | .unwrap_or_else(Vec::new), | ||
77 | }; | ||
78 | return Ok(Arc::new(submodules)); | ||
79 | |||
80 | fn collect_submodules<'a>( | ||
81 | db: &impl HirDatabase, | ||
82 | file_id: HirFileId, | ||
83 | root: impl ast::ModuleItemOwner<'a>, | ||
84 | ) -> Vec<Submodule> { | ||
85 | modules(root) | ||
86 | .map(|(name, m)| { | ||
87 | if m.has_semi() { | ||
88 | Submodule::Declaration(name) | ||
89 | } else { | ||
90 | let src = ModuleSource::new_inline(db, file_id, m); | ||
91 | Submodule::Definition(name, src) | ||
92 | } | ||
93 | }) | ||
94 | .collect() | ||
95 | } | ||
96 | } | ||
97 | |||
98 | pub(crate) fn modules<'a>( | ||
99 | root: impl ast::ModuleItemOwner<'a>, | ||
100 | ) -> impl Iterator<Item = (Name, ast::Module<'a>)> { | ||
101 | root.items() | ||
102 | .filter_map(|item| match item { | ||
103 | ast::ModuleItem::Module(m) => Some(m), | ||
104 | _ => None, | ||
105 | }) | ||
106 | .filter_map(|module| { | ||
107 | let name = module.name()?.as_name(); | ||
108 | Some((name, module)) | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | pub(super) fn input_module_items( | 61 | pub(super) fn input_module_items( |
113 | db: &impl HirDatabase, | 62 | db: &impl HirDatabase, |
114 | source_root_id: SourceRootId, | 63 | source_root_id: SourceRootId, |