aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-15 14:55:15 +0000
committerAleksey Kladov <[email protected]>2019-01-15 14:55:15 +0000
commit68ff52566d44e916868de1b52a9688182c26ebde (patch)
treee5776811753f66c50d98dd155199c9cadd6b2bfb /crates/ra_hir
parent443ff27724855ffbfccad3513bb82d59e1a4f8ae (diff)
remove Cancelable from module_tree_query
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs2
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs16
-rw-r--r--crates/ra_hir/src/db.rs4
-rw-r--r--crates/ra_hir/src/module_tree.rs31
-rw-r--r--crates/ra_hir/src/query_definitions.rs4
-rw-r--r--crates/ra_hir/src/source_binder.rs2
6 files changed, 28 insertions, 31 deletions
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs
index 3275eafed..712c6c86a 100644
--- a/crates/ra_hir/src/code_model_impl/krate.rs
+++ b/crates/ra_hir/src/code_model_impl/krate.rs
@@ -25,7 +25,7 @@ impl Crate {
25 let file_id = crate_graph.crate_root(self.crate_id); 25 let file_id = crate_graph.crate_root(self.crate_id);
26 let source_root_id = db.file_source_root(file_id); 26 let source_root_id = db.file_source_root(file_id);
27 let file_id = HirFileId::from(file_id); 27 let file_id = HirFileId::from(file_id);
28 let module_tree = db.module_tree(source_root_id)?; 28 let module_tree = db.module_tree(source_root_id);
29 // FIXME: teach module tree about crate roots instead of guessing 29 // FIXME: teach module tree about crate roots instead of guessing
30 let source = SourceItemId { 30 let source = SourceItemId {
31 file_id, 31 file_id,
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 775dd6709..2ec3ab469 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -19,7 +19,7 @@ impl Module {
19 source_root_id: SourceRootId, 19 source_root_id: SourceRootId,
20 module_id: ModuleId, 20 module_id: ModuleId,
21 ) -> Cancelable<Self> { 21 ) -> Cancelable<Self> {
22 let module_tree = db.module_tree(source_root_id)?; 22 let module_tree = db.module_tree(source_root_id);
23 let def_loc = DefLoc { 23 let def_loc = DefLoc {
24 kind: DefKind::Module, 24 kind: DefKind::Module,
25 source_root_id, 25 source_root_id,
@@ -33,7 +33,7 @@ impl Module {
33 33
34 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 34 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
35 let loc = self.def_id.loc(db); 35 let loc = self.def_id.loc(db);
36 let module_tree = db.module_tree(loc.source_root_id)?; 36 let module_tree = db.module_tree(loc.source_root_id);
37 let link = ctry!(loc.module_id.parent_link(&module_tree)); 37 let link = ctry!(loc.module_id.parent_link(&module_tree));
38 Ok(Some(link.name(&module_tree).clone())) 38 Ok(Some(link.name(&module_tree).clone()))
39 } 39 }
@@ -59,7 +59,7 @@ impl Module {
59 db: &impl HirDatabase, 59 db: &impl HirDatabase,
60 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> { 60 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> {
61 let loc = self.def_id.loc(db); 61 let loc = self.def_id.loc(db);
62 let module_tree = db.module_tree(loc.source_root_id)?; 62 let module_tree = db.module_tree(loc.source_root_id);
63 let link = ctry!(loc.module_id.parent_link(&module_tree)); 63 let link = ctry!(loc.module_id.parent_link(&module_tree));
64 let file_id = link 64 let file_id = link
65 .owner(&module_tree) 65 .owner(&module_tree)
@@ -82,7 +82,7 @@ impl Module {
82 82
83 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> { 83 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> {
84 let loc = self.def_id.loc(db); 84 let loc = self.def_id.loc(db);
85 let module_tree = db.module_tree(loc.source_root_id)?; 85 let module_tree = db.module_tree(loc.source_root_id);
86 let module_id = loc.module_id.crate_root(&module_tree); 86 let module_id = loc.module_id.crate_root(&module_tree);
87 Module::from_module_id(db, loc.source_root_id, module_id) 87 Module::from_module_id(db, loc.source_root_id, module_id)
88 } 88 }
@@ -90,7 +90,7 @@ impl Module {
90 /// Finds a child module with the specified name. 90 /// Finds a child module with the specified name.
91 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { 91 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
92 let loc = self.def_id.loc(db); 92 let loc = self.def_id.loc(db);
93 let module_tree = db.module_tree(loc.source_root_id)?; 93 let module_tree = db.module_tree(loc.source_root_id);
94 let child_id = ctry!(loc.module_id.child(&module_tree, name)); 94 let child_id = ctry!(loc.module_id.child(&module_tree, name));
95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some) 95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some)
96 } 96 }
@@ -101,7 +101,7 @@ impl Module {
101 // it's kind of hard since the iterator needs to keep a reference to the 101 // it's kind of hard since the iterator needs to keep a reference to the
102 // module tree. 102 // module tree.
103 let loc = self.def_id.loc(db); 103 let loc = self.def_id.loc(db);
104 let module_tree = db.module_tree(loc.source_root_id)?; 104 let module_tree = db.module_tree(loc.source_root_id);
105 let children = loc 105 let children = loc
106 .module_id 106 .module_id
107 .children(&module_tree) 107 .children(&module_tree)
@@ -112,7 +112,7 @@ impl Module {
112 112
113 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 113 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
114 let loc = self.def_id.loc(db); 114 let loc = self.def_id.loc(db);
115 let module_tree = db.module_tree(loc.source_root_id)?; 115 let module_tree = db.module_tree(loc.source_root_id);
116 let parent_id = ctry!(loc.module_id.parent(&module_tree)); 116 let parent_id = ctry!(loc.module_id.parent(&module_tree));
117 Module::from_module_id(db, loc.source_root_id, parent_id).map(Some) 117 Module::from_module_id(db, loc.source_root_id, parent_id).map(Some)
118 } 118 }
@@ -190,7 +190,7 @@ impl Module {
190 db: &impl HirDatabase, 190 db: &impl HirDatabase,
191 ) -> Cancelable<Vec<(TreeArc<SyntaxNode>, Problem)>> { 191 ) -> Cancelable<Vec<(TreeArc<SyntaxNode>, Problem)>> {
192 let loc = self.def_id.loc(db); 192 let loc = self.def_id.loc(db);
193 let module_tree = db.module_tree(loc.source_root_id)?; 193 let module_tree = db.module_tree(loc.source_root_id);
194 Ok(loc.module_id.problems(&module_tree, db)) 194 Ok(loc.module_id.problems(&module_tree, db))
195 } 195 }
196} 196}
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index fd6336dd8..68c3eb4e4 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -77,7 +77,7 @@ pub trait HirDatabase: SyntaxDatabase
77 use fn query_definitions::file_item; 77 use fn query_definitions::file_item;
78 } 78 }
79 79
80 fn submodules(source: SourceItemId) -> Cancelable<Arc<Vec<crate::module_tree::Submodule>>> { 80 fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> {
81 type SubmodulesQuery; 81 type SubmodulesQuery;
82 use fn crate::module_tree::Submodule::submodules_query; 82 use fn crate::module_tree::Submodule::submodules_query;
83 } 83 }
@@ -92,7 +92,7 @@ pub trait HirDatabase: SyntaxDatabase
92 use fn query_definitions::item_map; 92 use fn query_definitions::item_map;
93 } 93 }
94 94
95 fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { 95 fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> {
96 type ModuleTreeQuery; 96 type ModuleTreeQuery;
97 use fn crate::module_tree::ModuleTree::module_tree_query; 97 use fn crate::module_tree::ModuleTree::module_tree_query;
98 } 98 }
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs
index fd5a92c5b..0256d7996 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, Cancelable, SourceRoot}; 6use ra_db::{FileId, SourceRootId, SourceRoot};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNode, TreeArc, 8 SyntaxNode, TreeArc,
9 algo::generate, 9 algo::generate,
@@ -41,7 +41,7 @@ impl Submodule {
41 pub(crate) fn submodules_query( 41 pub(crate) fn submodules_query(
42 db: &impl HirDatabase, 42 db: &impl HirDatabase,
43 source: SourceItemId, 43 source: SourceItemId,
44 ) -> Cancelable<Arc<Vec<Submodule>>> { 44 ) -> Arc<Vec<Submodule>> {
45 db.check_canceled(); 45 db.check_canceled();
46 let file_id = source.file_id; 46 let file_id = source.file_id;
47 let file_items = db.file_items(file_id); 47 let file_items = db.file_items(file_id);
@@ -54,7 +54,7 @@ impl Submodule {
54 collect_submodules(file_id, &file_items, module.item_list().unwrap()) 54 collect_submodules(file_id, &file_items, module.item_list().unwrap())
55 } 55 }
56 }; 56 };
57 return Ok(Arc::new(submodules)); 57 return Arc::new(submodules);
58 58
59 fn collect_submodules( 59 fn collect_submodules(
60 file_id: HirFileId, 60 file_id: HirFileId,
@@ -116,10 +116,10 @@ impl ModuleTree {
116 pub(crate) fn module_tree_query( 116 pub(crate) fn module_tree_query(
117 db: &impl HirDatabase, 117 db: &impl HirDatabase,
118 source_root: SourceRootId, 118 source_root: SourceRootId,
119 ) -> Cancelable<Arc<ModuleTree>> { 119 ) -> Arc<ModuleTree> {
120 db.check_canceled(); 120 db.check_canceled();
121 let res = create_module_tree(db, source_root); 121 let res = create_module_tree(db, source_root);
122 Ok(Arc::new(res?)) 122 Arc::new(res)
123 } 123 }
124 124
125 pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { 125 pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a {
@@ -225,10 +225,7 @@ fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast
225 }) 225 })
226} 226}
227 227
228fn create_module_tree<'a>( 228fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree {
229 db: &impl HirDatabase,
230 source_root: SourceRootId,
231) -> Cancelable<ModuleTree> {
232 let mut tree = ModuleTree::default(); 229 let mut tree = ModuleTree::default();
233 230
234 let mut roots = FxHashMap::default(); 231 let mut roots = FxHashMap::default();
@@ -252,10 +249,10 @@ fn create_module_tree<'a>(
252 &mut roots, 249 &mut roots,
253 None, 250 None,
254 source, 251 source,
255 )?; 252 );
256 roots.insert(file_id, module_id); 253 roots.insert(file_id, module_id);
257 } 254 }
258 Ok(tree) 255 tree
259} 256}
260 257
261fn build_subtree( 258fn build_subtree(
@@ -266,14 +263,14 @@ fn build_subtree(
266 roots: &mut FxHashMap<FileId, ModuleId>, 263 roots: &mut FxHashMap<FileId, ModuleId>,
267 parent: Option<LinkId>, 264 parent: Option<LinkId>,
268 source: SourceItemId, 265 source: SourceItemId,
269) -> Cancelable<ModuleId> { 266) -> ModuleId {
270 visited.insert(source); 267 visited.insert(source);
271 let id = tree.push_mod(ModuleData { 268 let id = tree.push_mod(ModuleData {
272 source, 269 source,
273 parent, 270 parent,
274 children: Vec::new(), 271 children: Vec::new(),
275 }); 272 });
276 for sub in db.submodules(source)?.iter() { 273 for sub in db.submodules(source).iter() {
277 let link = tree.push_link(LinkData { 274 let link = tree.push_link(LinkData {
278 source: sub.source, 275 source: sub.source,
279 name: sub.name.clone(), 276 name: sub.name.clone(),
@@ -289,7 +286,7 @@ fn build_subtree(
289 .map(|file_id| match roots.remove(&file_id) { 286 .map(|file_id| match roots.remove(&file_id) {
290 Some(module_id) => { 287 Some(module_id) => {
291 tree.mods[module_id].parent = Some(link); 288 tree.mods[module_id].parent = Some(link);
292 Ok(module_id) 289 module_id
293 } 290 }
294 None => build_subtree( 291 None => build_subtree(
295 db, 292 db,
@@ -304,7 +301,7 @@ fn build_subtree(
304 }, 301 },
305 ), 302 ),
306 }) 303 })
307 .collect::<Cancelable<Vec<_>>>()?; 304 .collect::<Vec<_>>();
308 (points_to, problem) 305 (points_to, problem)
309 } else { 306 } else {
310 let points_to = build_subtree( 307 let points_to = build_subtree(
@@ -315,14 +312,14 @@ fn build_subtree(
315 roots, 312 roots,
316 Some(link), 313 Some(link),
317 sub.source, 314 sub.source,
318 )?; 315 );
319 (vec![points_to], None) 316 (vec![points_to], None)
320 }; 317 };
321 318
322 tree.links[link].points_to = points_to; 319 tree.links[link].points_to = points_to;
323 tree.links[link].problem = problem; 320 tree.links[link].problem = problem;
324 } 321 }
325 Ok(id) 322 id
326} 323}
327 324
328fn resolve_submodule( 325fn resolve_submodule(
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 214a9d68b..d84efbf95 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -48,7 +48,7 @@ pub(super) fn input_module_items(
48 source_root_id: SourceRootId, 48 source_root_id: SourceRootId,
49 module_id: ModuleId, 49 module_id: ModuleId,
50) -> Cancelable<Arc<InputModuleItems>> { 50) -> Cancelable<Arc<InputModuleItems>> {
51 let module_tree = db.module_tree(source_root_id)?; 51 let module_tree = db.module_tree(source_root_id);
52 let source = module_id.source(&module_tree); 52 let source = module_id.source(&module_tree);
53 let file_id = source.file_id; 53 let file_id = source.file_id;
54 let source = ModuleSource::from_source_item_id(db, source); 54 let source = ModuleSource::from_source_item_id(db, source);
@@ -98,7 +98,7 @@ pub(super) fn item_map(
98 source_root: SourceRootId, 98 source_root: SourceRootId,
99) -> Cancelable<Arc<ItemMap>> { 99) -> Cancelable<Arc<ItemMap>> {
100 let start = Instant::now(); 100 let start = Instant::now();
101 let module_tree = db.module_tree(source_root)?; 101 let module_tree = db.module_tree(source_root);
102 let input = module_tree 102 let input = module_tree
103 .modules() 103 .modules()
104 .map(|id| { 104 .map(|id| {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 1f149a366..70dd850d7 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -92,7 +92,7 @@ pub fn module_from_child_node(
92 92
93fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> { 93fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> {
94 let source_root_id = db.file_source_root(source.file_id.as_original_file()); 94 let source_root_id = db.file_source_root(source.file_id.as_original_file());
95 let module_tree = db.module_tree(source_root_id)?; 95 let module_tree = db.module_tree(source_root_id);
96 let module_id = ctry!(module_tree.find_module_by_source(source)); 96 let module_id = ctry!(module_tree.find_module_by_source(source));
97 Ok(Some(Module::from_module_id(db, source_root_id, module_id)?)) 97 Ok(Some(Module::from_module_id(db, source_root_id, module_id)?))
98} 98}