diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 19 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 28 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/scope.rs | 12 |
3 files changed, 20 insertions, 39 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index 5fdaad137..dae3a356d 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -10,14 +10,15 @@ use ra_syntax::{ | |||
10 | use crate::{ | 10 | use crate::{ |
11 | FileId, Cancelable, FileResolverImp, db, | 11 | FileId, Cancelable, FileResolverImp, db, |
12 | input::{SourceRoot, SourceRootId}, | 12 | input::{SourceRoot, SourceRootId}, |
13 | descriptors::DescriptorDatabase, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | use super::{ | 16 | use super::{ |
16 | ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModulesDatabase, ModuleScope | 17 | ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModuleScope |
17 | }; | 18 | }; |
18 | 19 | ||
19 | 20 | ||
20 | pub(super) fn submodules(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> { | 21 | pub(crate) fn submodules(db: &impl DescriptorDatabase, file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> { |
21 | db::check_canceled(db)?; | 22 | db::check_canceled(db)?; |
22 | let file = db.file_syntax(file_id); | 23 | let file = db.file_syntax(file_id); |
23 | let root = file.ast(); | 24 | let root = file.ast(); |
@@ -25,7 +26,7 @@ pub(super) fn submodules(db: &impl ModulesDatabase, file_id: FileId) -> Cancelab | |||
25 | Ok(Arc::new(submodules)) | 26 | Ok(Arc::new(submodules)) |
26 | } | 27 | } |
27 | 28 | ||
28 | pub(super) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { | 29 | pub(crate) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { |
29 | root.modules().filter_map(|module| { | 30 | root.modules().filter_map(|module| { |
30 | let name = module.name()?.text(); | 31 | let name = module.name()?.text(); |
31 | if !module.has_semi() { | 32 | if !module.has_semi() { |
@@ -35,8 +36,8 @@ pub(super) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast | |||
35 | }) | 36 | }) |
36 | } | 37 | } |
37 | 38 | ||
38 | pub(super) fn module_scope( | 39 | pub(crate) fn module_scope( |
39 | db: &impl ModulesDatabase, | 40 | db: &impl DescriptorDatabase, |
40 | source_root_id: SourceRootId, | 41 | source_root_id: SourceRootId, |
41 | module_id: ModuleId, | 42 | module_id: ModuleId, |
42 | ) -> Cancelable<Arc<ModuleScope>> { | 43 | ) -> Cancelable<Arc<ModuleScope>> { |
@@ -47,8 +48,8 @@ pub(super) fn module_scope( | |||
47 | Ok(Arc::new(res)) | 48 | Ok(Arc::new(res)) |
48 | } | 49 | } |
49 | 50 | ||
50 | pub(super) fn module_tree( | 51 | pub(crate) fn module_tree( |
51 | db: &impl ModulesDatabase, | 52 | db: &impl DescriptorDatabase, |
52 | source_root: SourceRootId, | 53 | source_root: SourceRootId, |
53 | ) -> Cancelable<Arc<ModuleTree>> { | 54 | ) -> Cancelable<Arc<ModuleTree>> { |
54 | db::check_canceled(db)?; | 55 | db::check_canceled(db)?; |
@@ -64,7 +65,7 @@ pub struct Submodule { | |||
64 | 65 | ||
65 | 66 | ||
66 | fn create_module_tree<'a>( | 67 | fn create_module_tree<'a>( |
67 | db: &impl ModulesDatabase, | 68 | db: &impl DescriptorDatabase, |
68 | source_root: SourceRootId, | 69 | source_root: SourceRootId, |
69 | ) -> Cancelable<ModuleTree> { | 70 | ) -> Cancelable<ModuleTree> { |
70 | let mut tree = ModuleTree { | 71 | let mut tree = ModuleTree { |
@@ -88,7 +89,7 @@ fn create_module_tree<'a>( | |||
88 | } | 89 | } |
89 | 90 | ||
90 | fn build_subtree( | 91 | fn build_subtree( |
91 | db: &impl ModulesDatabase, | 92 | db: &impl DescriptorDatabase, |
92 | source_root: &SourceRoot, | 93 | source_root: &SourceRoot, |
93 | tree: &mut ModuleTree, | 94 | tree: &mut ModuleTree, |
94 | visited: &mut FxHashSet<FileId>, | 95 | visited: &mut FxHashSet<FileId>, |
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 9e5d73f94..667553f74 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -1,37 +1,13 @@ | |||
1 | mod imp; | 1 | pub(super) mod imp; |
2 | pub(crate) mod scope; | 2 | pub(crate) mod scope; |
3 | 3 | ||
4 | use std::sync::Arc; | ||
5 | |||
6 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
7 | use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; | 5 | use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; |
8 | 6 | ||
9 | use crate::{ | 7 | use crate::FileId; |
10 | FileId, Cancelable, | ||
11 | db::SyntaxDatabase, | ||
12 | input::SourceRootId, | ||
13 | }; | ||
14 | 8 | ||
15 | pub(crate) use self::scope::ModuleScope; | 9 | pub(crate) use self::scope::ModuleScope; |
16 | 10 | ||
17 | salsa::query_group! { | ||
18 | pub(crate) trait ModulesDatabase: SyntaxDatabase { | ||
19 | fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { | ||
20 | type ModuleTreeQuery; | ||
21 | use fn imp::module_tree; | ||
22 | } | ||
23 | fn submodules(file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> { | ||
24 | type SubmodulesQuery; | ||
25 | use fn imp::submodules; | ||
26 | } | ||
27 | fn module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleScope>> { | ||
28 | type ModuleScopeQuery; | ||
29 | use fn imp::module_scope; | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | |||
34 | |||
35 | #[derive(Debug, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, PartialEq, Eq, Hash)] |
36 | pub(crate) struct ModuleTree { | 12 | pub(crate) struct ModuleTree { |
37 | mods: Vec<ModuleData>, | 13 | mods: Vec<ModuleData>, |
diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs index da58ddce0..846b8b44f 100644 --- a/crates/ra_analysis/src/descriptors/module/scope.rs +++ b/crates/ra_analysis/src/descriptors/module/scope.rs | |||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | 3 | ||
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | ast::{self, AstChildren, ModuleItemOwner}, | 5 | ast::{self, ModuleItemOwner}, |
6 | File, AstNode, SmolStr, SyntaxNode, SyntaxNodeRef, | 6 | File, AstNode, SmolStr, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crate::syntax_ptr::LocalSyntaxPtr; | 9 | use crate::syntax_ptr::LocalSyntaxPtr; |
@@ -30,8 +30,12 @@ enum EntryKind { | |||
30 | 30 | ||
31 | impl ModuleScope { | 31 | impl ModuleScope { |
32 | pub fn new(file: &File) -> ModuleScope { | 32 | pub fn new(file: &File) -> ModuleScope { |
33 | ModuleScope::from_items(file.ast().items()) | ||
34 | } | ||
35 | |||
36 | pub fn from_items<'a>(items: impl Iterator<Item = ast::ModuleItem<'a>>) -> ModuleScope { | ||
33 | let mut entries = Vec::new(); | 37 | let mut entries = Vec::new(); |
34 | for item in file.ast().items() { | 38 | for item in items { |
35 | let entry = match item { | 39 | let entry = match item { |
36 | ast::ModuleItem::StructDef(item) => Entry::new(item), | 40 | ast::ModuleItem::StructDef(item) => Entry::new(item), |
37 | ast::ModuleItem::EnumDef(item) => Entry::new(item), | 41 | ast::ModuleItem::EnumDef(item) => Entry::new(item), |
@@ -99,7 +103,7 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) { | |||
99 | #[cfg(test)] | 103 | #[cfg(test)] |
100 | mod tests { | 104 | mod tests { |
101 | use super::*; | 105 | use super::*; |
102 | use ra_syntax::{ast::ModuleItemOwner, File}; | 106 | use ra_syntax::{File}; |
103 | 107 | ||
104 | fn do_check(code: &str, expected: &[&str]) { | 108 | fn do_check(code: &str, expected: &[&str]) { |
105 | let file = File::parse(&code); | 109 | let file = File::parse(&code); |