aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r--crates/ra_analysis/src/descriptors/module/imp.rs19
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs28
-rw-r--r--crates/ra_analysis/src/descriptors/module/scope.rs6
3 files changed, 15 insertions, 38 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::{
10use crate::{ 10use 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
15use super::{ 16use super::{
16 ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModulesDatabase, ModuleScope 17 ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModuleScope
17}; 18};
18 19
19 20
20pub(super) fn submodules(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> { 21pub(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
28pub(super) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { 29pub(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
38pub(super) fn module_scope( 39pub(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
50pub(super) fn module_tree( 51pub(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
66fn create_module_tree<'a>( 67fn 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
90fn build_subtree( 91fn 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 @@
1mod imp; 1pub(super) mod imp;
2pub(crate) mod scope; 2pub(crate) mod scope;
3 3
4use std::sync::Arc;
5
6use relative_path::RelativePathBuf; 4use relative_path::RelativePathBuf;
7use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; 5use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode};
8 6
9use crate::{ 7use crate::FileId;
10 FileId, Cancelable,
11 db::SyntaxDatabase,
12 input::SourceRootId,
13};
14 8
15pub(crate) use self::scope::ModuleScope; 9pub(crate) use self::scope::ModuleScope;
16 10
17salsa::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)]
36pub(crate) struct ModuleTree { 12pub(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..0f8f325ab 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
4use ra_syntax::{ 4use 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
9use crate::syntax_ptr::LocalSyntaxPtr; 9use crate::syntax_ptr::LocalSyntaxPtr;
@@ -99,7 +99,7 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {
99#[cfg(test)] 99#[cfg(test)]
100mod tests { 100mod tests {
101 use super::*; 101 use super::*;
102 use ra_syntax::{ast::ModuleItemOwner, File}; 102 use ra_syntax::{File};
103 103
104 fn do_check(code: &str, expected: &[&str]) { 104 fn do_check(code: &str, expected: &[&str]) {
105 let file = File::parse(&code); 105 let file = File::parse(&code);