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 | |
parent | 17b2994b99394562b5e515c953a3a83c5977da76 (diff) |
move submodule computationt to module_tree
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model_impl.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/module_tree.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 54 |
4 files changed, 39 insertions, 53 deletions
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs index d602a439d..157b0c616 100644 --- a/crates/ra_hir/src/code_model_impl.rs +++ b/crates/ra_hir/src/code_model_impl.rs | |||
@@ -1,2 +1,2 @@ | |||
1 | mod krate; // `crate` is invalid ident :( | 1 | mod krate; // `crate` is invalid ident :( |
2 | pub(crate) mod module; | 2 | mod module; |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 2702961ba..e4249de14 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -73,7 +73,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
73 | 73 | ||
74 | fn submodules(source: ModuleSource) -> Cancelable<Arc<Vec<crate::module_tree::Submodule>>> { | 74 | fn submodules(source: ModuleSource) -> Cancelable<Arc<Vec<crate::module_tree::Submodule>>> { |
75 | type SubmodulesQuery; | 75 | type SubmodulesQuery; |
76 | use fn query_definitions::submodules; | 76 | use fn crate::module_tree::Submodule::submodules_query; |
77 | } | 77 | } |
78 | 78 | ||
79 | fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> { | 79 | fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> { |
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index cd82f25db..b7912ba5e 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs | |||
@@ -20,6 +20,40 @@ pub enum Submodule { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | impl Submodule { | 22 | impl Submodule { |
23 | pub(crate) fn submodules_query( | ||
24 | db: &impl HirDatabase, | ||
25 | source: ModuleSource, | ||
26 | ) -> Cancelable<Arc<Vec<Submodule>>> { | ||
27 | db.check_canceled()?; | ||
28 | let file_id = source.file_id(); | ||
29 | let submodules = match source.resolve(db) { | ||
30 | ModuleSourceNode::SourceFile(it) => collect_submodules(db, file_id, it.borrowed()), | ||
31 | ModuleSourceNode::Module(it) => it | ||
32 | .borrowed() | ||
33 | .item_list() | ||
34 | .map(|it| collect_submodules(db, file_id, it)) | ||
35 | .unwrap_or_else(Vec::new), | ||
36 | }; | ||
37 | return Ok(Arc::new(submodules)); | ||
38 | |||
39 | fn collect_submodules<'a>( | ||
40 | db: &impl HirDatabase, | ||
41 | file_id: HirFileId, | ||
42 | root: impl ast::ModuleItemOwner<'a>, | ||
43 | ) -> Vec<Submodule> { | ||
44 | modules(root) | ||
45 | .map(|(name, m)| { | ||
46 | if m.has_semi() { | ||
47 | Submodule::Declaration(name) | ||
48 | } else { | ||
49 | let src = ModuleSource::new_inline(db, file_id, m); | ||
50 | Submodule::Definition(name, src) | ||
51 | } | ||
52 | }) | ||
53 | .collect() | ||
54 | } | ||
55 | } | ||
56 | |||
23 | fn name(&self) -> &Name { | 57 | fn name(&self) -> &Name { |
24 | match self { | 58 | match self { |
25 | Submodule::Declaration(name) => name, | 59 | Submodule::Declaration(name) => name, |
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, |