aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/module_tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/module_tree.rs')
-rw-r--r--crates/ra_hir/src/module_tree.rs36
1 files changed, 15 insertions, 21 deletions
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs
index b201bf69b..c00834c4c 100644
--- a/crates/ra_hir/src/module_tree.rs
+++ b/crates/ra_hir/src/module_tree.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4use arrayvec::ArrayVec; 4use arrayvec::ArrayVec;
5use relative_path::RelativePathBuf; 5use relative_path::RelativePathBuf;
6use ra_db::{FileId, SourceRootId, SourceRoot}; 6use ra_db::{FileId, SourceRoot, CrateId};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNode, TreeArc, 8 SyntaxNode, TreeArc,
9 algo::generate, 9 algo::generate,
@@ -126,13 +126,10 @@ struct LinkData {
126} 126}
127 127
128impl ModuleTree { 128impl ModuleTree {
129 pub(crate) fn module_tree_query( 129 pub(crate) fn module_tree_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ModuleTree> {
130 db: &impl HirDatabase,
131 source_root: SourceRootId,
132 ) -> Arc<ModuleTree> {
133 db.check_canceled(); 130 db.check_canceled();
134 let mut res = ModuleTree::default(); 131 let mut res = ModuleTree::default();
135 res.init(db, source_root); 132 res.init_crate(db, crate_id);
136 Arc::new(res) 133 Arc::new(res)
137 } 134 }
138 135
@@ -145,24 +142,21 @@ impl ModuleTree {
145 Some(res) 142 Some(res)
146 } 143 }
147 144
148 fn init(&mut self, db: &impl HirDatabase, source_root: SourceRootId) { 145 fn init_crate(&mut self, db: &impl HirDatabase, crate_id: CrateId) {
146 let crate_graph = db.crate_graph();
147 let file_id = crate_graph.crate_root(crate_id);
148 let source_root_id = db.file_source_root(file_id);
149
149 let mut roots = FxHashMap::default(); 150 let mut roots = FxHashMap::default();
150 let mut visited = FxHashSet::default(); 151 let mut visited = FxHashSet::default();
151 152
152 let source_root = db.source_root(source_root); 153 let source_root = db.source_root(source_root_id);
153 for &file_id in source_root.files.values() { 154 let source = SourceItemId {
154 let source = SourceItemId { 155 file_id: file_id.into(),
155 file_id: file_id.into(), 156 item_id: None,
156 item_id: None, 157 };
157 }; 158 let module_id = self.init_subtree(db, &source_root, &mut visited, &mut roots, None, source);
158 if visited.contains(&source) { 159 roots.insert(file_id, module_id);
159 continue; // TODO: use explicit crate_roots here
160 }
161 assert!(!roots.contains_key(&file_id));
162 let module_id =
163 self.init_subtree(db, &source_root, &mut visited, &mut roots, None, source);
164 roots.insert(file_id, module_id);
165 }
166 } 160 }
167 161
168 fn init_subtree( 162 fn init_subtree(