aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module/imp.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-25 16:04:48 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-25 16:04:48 +0100
commit5932bd0bb5fcd066a9d16abcd1597b7097978085 (patch)
tree7b6ea86855fe34c3d45d14262c8cf94e315566e8 /crates/ra_analysis/src/descriptors/module/imp.rs
parent2cb2074c4b7219b32993abdcc7084637c0123d49 (diff)
parent363adf07b7763cfe7e13fac0ee148361d51834e4 (diff)
Merge #162
162: Db everywhere r=matklad a=matklad This PR continues our switch to salsa. Now *all* state is handled by a single salsa database. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/imp.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/module/imp.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs
index 22e4bd785..aecf6e29a 100644
--- a/crates/ra_analysis/src/descriptors/module/imp.rs
+++ b/crates/ra_analysis/src/descriptors/module/imp.rs
@@ -8,8 +8,8 @@ use ra_syntax::{
8}; 8};
9 9
10use crate::{ 10use crate::{
11 FileId, Cancelable, FileResolverImp, 11 FileId, Cancelable, FileResolverImp, db,
12 db, 12 input::{SourceRoot, SourceRootId},
13}; 13};
14 14
15use super::{ 15use super::{
@@ -35,9 +35,12 @@ pub(super) fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast
35 }) 35 })
36} 36}
37 37
38pub(super) fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTree>> { 38pub(super) fn module_tree(
39 db: &impl ModulesDatabase,
40 source_root: SourceRootId,
41) -> Cancelable<Arc<ModuleTree>> {
39 db::check_canceled(db)?; 42 db::check_canceled(db)?;
40 let res = create_module_tree(db)?; 43 let res = create_module_tree(db, source_root)?;
41 Ok(Arc::new(res)) 44 Ok(Arc::new(res))
42} 45}
43 46
@@ -50,6 +53,7 @@ pub struct Submodule {
50 53
51fn create_module_tree<'a>( 54fn create_module_tree<'a>(
52 db: &impl ModulesDatabase, 55 db: &impl ModulesDatabase,
56 source_root: SourceRootId,
53) -> Cancelable<ModuleTree> { 57) -> Cancelable<ModuleTree> {
54 let mut tree = ModuleTree { 58 let mut tree = ModuleTree {
55 mods: Vec::new(), 59 mods: Vec::new(),
@@ -59,12 +63,13 @@ fn create_module_tree<'a>(
59 let mut roots = FxHashMap::default(); 63 let mut roots = FxHashMap::default();
60 let mut visited = FxHashSet::default(); 64 let mut visited = FxHashSet::default();
61 65
62 for &file_id in db.file_set().files.iter() { 66 let source_root = db.source_root(source_root);
67 for &file_id in source_root.files.iter() {
63 if visited.contains(&file_id) { 68 if visited.contains(&file_id) {
64 continue; // TODO: use explicit crate_roots here 69 continue; // TODO: use explicit crate_roots here
65 } 70 }
66 assert!(!roots.contains_key(&file_id)); 71 assert!(!roots.contains_key(&file_id));
67 let module_id = build_subtree(db, &mut tree, &mut visited, &mut roots, None, file_id)?; 72 let module_id = build_subtree(db, &source_root, &mut tree, &mut visited, &mut roots, None, file_id)?;
68 roots.insert(file_id, module_id); 73 roots.insert(file_id, module_id);
69 } 74 }
70 Ok(tree) 75 Ok(tree)
@@ -72,6 +77,7 @@ fn create_module_tree<'a>(
72 77
73fn build_subtree( 78fn build_subtree(
74 db: &impl ModulesDatabase, 79 db: &impl ModulesDatabase,
80 source_root: &SourceRoot,
75 tree: &mut ModuleTree, 81 tree: &mut ModuleTree,
76 visited: &mut FxHashSet<FileId>, 82 visited: &mut FxHashSet<FileId>,
77 roots: &mut FxHashMap<FileId, ModuleId>, 83 roots: &mut FxHashMap<FileId, ModuleId>,
@@ -84,10 +90,8 @@ fn build_subtree(
84 parent, 90 parent,
85 children: Vec::new(), 91 children: Vec::new(),
86 }); 92 });
87 let file_set = db.file_set();
88 let file_resolver = &file_set.resolver;
89 for name in db.submodules(file_id)?.iter() { 93 for name in db.submodules(file_id)?.iter() {
90 let (points_to, problem) = resolve_submodule(file_id, name, file_resolver); 94 let (points_to, problem) = resolve_submodule(file_id, name, &source_root.file_resolver);
91 let link = tree.push_link(LinkData { 95 let link = tree.push_link(LinkData {
92 name: name.clone(), 96 name: name.clone(),
93 owner: id, 97 owner: id,
@@ -102,7 +106,7 @@ fn build_subtree(
102 tree.module_mut(module_id).parent = Some(link); 106 tree.module_mut(module_id).parent = Some(link);
103 Ok(module_id) 107 Ok(module_id)
104 } 108 }
105 None => build_subtree(db, tree, visited, roots, Some(link), file_id), 109 None => build_subtree(db, source_root, tree, visited, roots, Some(link), file_id),
106 }) 110 })
107 .collect::<Cancelable<Vec<_>>>()?; 111 .collect::<Cancelable<Vec<_>>>()?;
108 tree.link_mut(link).points_to = points_to; 112 tree.link_mut(link).points_to = points_to;