aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:19:40 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:19:40 +0000
commit91feed736f91a3790b2f5a5d0d879c06843bce95 (patch)
tree6a71bcb433b82e4c473238d439aad2ef76144157 /crates
parenta36b2cf377a90cf13bb097e57878b8384d30c53a (diff)
parentfb012e5c1e49af73b480127bcf56d8f5993b8032 (diff)
Merge #550
550: remove Cancelable from source binders r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs2
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs21
-rw-r--r--crates/ra_hir/src/db.rs2
-rw-r--r--crates/ra_hir/src/ids.rs8
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_hir/src/nameres/tests.rs16
-rw-r--r--crates/ra_hir/src/query_definitions.rs11
-rw-r--r--crates/ra_hir/src/source_binder.rs62
-rw-r--r--crates/ra_hir/src/ty/tests.rs8
-rw-r--r--crates/ra_ide_api/src/call_info.rs2
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs9
-rw-r--r--crates/ra_ide_api/src/hover.rs2
-rw-r--r--crates/ra_ide_api/src/imp.rs10
-rw-r--r--crates/ra_ide_api/src/lib.rs7
-rw-r--r--crates/ra_ide_api/src/parent_module.rs2
-rw-r--r--crates/ra_ide_api/src/runnables.rs3
-rw-r--r--crates/ra_ide_api/src/symbol_index.rs15
18 files changed, 80 insertions, 104 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 91b235594..5db53a34f 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -109,7 +109,7 @@ impl Module {
109 } 109 }
110 110
111 /// Finds a child module with the specified name. 111 /// Finds a child module with the specified name.
112 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { 112 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
113 self.child_impl(db, name) 113 self.child_impl(db, name)
114 } 114 }
115 115
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 2ec3ab469..67808d282 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -18,7 +18,7 @@ impl Module {
18 db: &impl HirDatabase, 18 db: &impl HirDatabase,
19 source_root_id: SourceRootId, 19 source_root_id: SourceRootId,
20 module_id: ModuleId, 20 module_id: ModuleId,
21 ) -> Cancelable<Self> { 21 ) -> 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,
@@ -27,8 +27,7 @@ impl Module {
27 source_item_id: module_id.source(&module_tree), 27 source_item_id: module_id.source(&module_tree),
28 }; 28 };
29 let def_id = def_loc.id(db); 29 let def_id = def_loc.id(db);
30 let module = Module::new(def_id); 30 Module::new(def_id)
31 Ok(module)
32 } 31 }
33 32
34 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
@@ -84,15 +83,15 @@ impl Module {
84 let loc = self.def_id.loc(db); 83 let loc = self.def_id.loc(db);
85 let module_tree = db.module_tree(loc.source_root_id); 84 let module_tree = db.module_tree(loc.source_root_id);
86 let module_id = loc.module_id.crate_root(&module_tree); 85 let module_id = loc.module_id.crate_root(&module_tree);
87 Module::from_module_id(db, loc.source_root_id, module_id) 86 Ok(Module::from_module_id(db, loc.source_root_id, module_id))
88 } 87 }
89 88
90 /// Finds a child module with the specified name. 89 /// Finds a child module with the specified name.
91 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { 90 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
92 let loc = self.def_id.loc(db); 91 let loc = self.def_id.loc(db);
93 let module_tree = db.module_tree(loc.source_root_id); 92 let module_tree = db.module_tree(loc.source_root_id);
94 let child_id = ctry!(loc.module_id.child(&module_tree, name)); 93 let child_id = loc.module_id.child(&module_tree, name)?;
95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some) 94 Some(Module::from_module_id(db, loc.source_root_id, child_id))
96 } 95 }
97 96
98 /// Iterates over all child modules. 97 /// Iterates over all child modules.
@@ -106,7 +105,7 @@ impl Module {
106 .module_id 105 .module_id
107 .children(&module_tree) 106 .children(&module_tree)
108 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) 107 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
109 .collect::<Cancelable<Vec<_>>>()?; 108 .collect::<Vec<_>>();
110 Ok(children.into_iter()) 109 Ok(children.into_iter())
111 } 110 }
112 111
@@ -114,7 +113,11 @@ impl Module {
114 let loc = self.def_id.loc(db); 113 let loc = self.def_id.loc(db);
115 let module_tree = db.module_tree(loc.source_root_id); 114 let module_tree = db.module_tree(loc.source_root_id);
116 let parent_id = ctry!(loc.module_id.parent(&module_tree)); 115 let parent_id = ctry!(loc.module_id.parent(&module_tree));
117 Module::from_module_id(db, loc.source_root_id, parent_id).map(Some) 116 Ok(Some(Module::from_module_id(
117 db,
118 loc.source_root_id,
119 parent_id,
120 )))
118 } 121 }
119 122
120 /// Returns a `ModuleScope`: a set of items, visible in this module. 123 /// Returns a `ModuleScope`: a set of items, visible in this module.
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 68c3eb4e4..3b2498d5a 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -82,7 +82,7 @@ pub trait HirDatabase: SyntaxDatabase
82 use fn crate::module_tree::Submodule::submodules_query; 82 use fn crate::module_tree::Submodule::submodules_query;
83 } 83 }
84 84
85 fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> { 85 fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> {
86 type InputModuleItemsQuery; 86 type InputModuleItemsQuery;
87 use fn query_definitions::input_module_items; 87 use fn query_definitions::input_module_items;
88 } 88 }
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 316896dce..d7cc9b4ca 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -163,7 +163,7 @@ impl DefId {
163 let loc = self.loc(db); 163 let loc = self.loc(db);
164 let res = match loc.kind { 164 let res = match loc.kind {
165 DefKind::Module => { 165 DefKind::Module => {
166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id)?; 166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id);
167 Def::Module(module) 167 Def::Module(module)
168 } 168 }
169 DefKind::Function => { 169 DefKind::Function => {
@@ -208,7 +208,11 @@ impl DefId {
208 /// For a module, returns that module; for any other def, returns the containing module. 208 /// For a module, returns that module; for any other def, returns the containing module.
209 pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { 209 pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
210 let loc = self.loc(db); 210 let loc = self.loc(db);
211 Module::from_module_id(db, loc.source_root_id, loc.module_id) 211 Ok(Module::from_module_id(
212 db,
213 loc.source_root_id,
214 loc.module_id,
215 ))
212 } 216 }
213 217
214 /// Returns the containing crate. 218 /// Returns the containing crate.
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index d0b086308..c9a9fb99f 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -196,7 +196,7 @@ pub(crate) fn impls_in_module(
196 module_id: ModuleId, 196 module_id: ModuleId,
197) -> Cancelable<Arc<ModuleImplBlocks>> { 197) -> Cancelable<Arc<ModuleImplBlocks>> {
198 let mut result = ModuleImplBlocks::new(); 198 let mut result = ModuleImplBlocks::new();
199 let module = Module::from_module_id(db, source_root_id, module_id)?; 199 let module = Module::from_module_id(db, source_root_id, module_id);
200 result.collect(db, module)?; 200 result.collect(db, module)?;
201 Ok(Arc::new(result)) 201 Ok(Arc::new(result))
202} 202}
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 647fd92aa..ea8ab4c83 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -15,9 +15,7 @@ use crate::{
15fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { 15fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
16 let (db, pos) = MockDatabase::with_position(fixture); 16 let (db, pos) = MockDatabase::with_position(fixture);
17 let source_root = db.file_source_root(pos.file_id); 17 let source_root = db.file_source_root(pos.file_id);
18 let module = crate::source_binder::module_from_position(&db, pos) 18 let module = crate::source_binder::module_from_position(&db, pos).unwrap();
19 .unwrap()
20 .unwrap();
21 let module_id = module.def_id.loc(&db).module_id; 19 let module_id = module.def_id.loc(&db).module_id;
22 (db.item_map(source_root).unwrap(), module_id) 20 (db.item_map(source_root).unwrap(), module_id)
23} 21}
@@ -242,9 +240,7 @@ fn item_map_across_crates() {
242 db.set_crate_graph(crate_graph); 240 db.set_crate_graph(crate_graph);
243 241
244 let source_root = db.file_source_root(main_id); 242 let source_root = db.file_source_root(main_id);
245 let module = crate::source_binder::module_from_file_id(&db, main_id) 243 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
246 .unwrap()
247 .unwrap();
248 let module_id = module.def_id.loc(&db).module_id; 244 let module_id = module.def_id.loc(&db).module_id;
249 let item_map = db.item_map(source_root).unwrap(); 245 let item_map = db.item_map(source_root).unwrap();
250 246
@@ -296,9 +292,7 @@ fn import_across_source_roots() {
296 292
297 db.set_crate_graph(crate_graph); 293 db.set_crate_graph(crate_graph);
298 294
299 let module = crate::source_binder::module_from_file_id(&db, main_id) 295 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
300 .unwrap()
301 .unwrap();
302 let module_id = module.def_id.loc(&db).module_id; 296 let module_id = module.def_id.loc(&db).module_id;
303 let item_map = db.item_map(source_root).unwrap(); 297 let item_map = db.item_map(source_root).unwrap();
304 298
@@ -341,9 +335,7 @@ fn reexport_across_crates() {
341 db.set_crate_graph(crate_graph); 335 db.set_crate_graph(crate_graph);
342 336
343 let source_root = db.file_source_root(main_id); 337 let source_root = db.file_source_root(main_id);
344 let module = crate::source_binder::module_from_file_id(&db, main_id) 338 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
345 .unwrap()
346 .unwrap();
347 let module_id = module.def_id.loc(&db).module_id; 339 let module_id = module.def_id.loc(&db).module_id;
348 let item_map = db.item_map(source_root).unwrap(); 340 let item_map = db.item_map(source_root).unwrap();
349 341
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index d84efbf95..7ff942f6a 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -47,7 +47,7 @@ pub(super) fn input_module_items(
47 db: &impl HirDatabase, 47 db: &impl HirDatabase,
48 source_root_id: SourceRootId, 48 source_root_id: SourceRootId,
49 module_id: ModuleId, 49 module_id: ModuleId,
50) -> Cancelable<Arc<InputModuleItems>> { 50) -> 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;
@@ -90,7 +90,7 @@ pub(super) fn input_module_items(
90 } 90 }
91 } 91 }
92 }; 92 };
93 Ok(Arc::new(res)) 93 Arc::new(res)
94} 94}
95 95
96pub(super) fn item_map( 96pub(super) fn item_map(
@@ -101,11 +101,8 @@ pub(super) fn item_map(
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| (id, db.input_module_items(source_root, id)))
105 let items = db.input_module_items(source_root, id)?; 105 .collect::<FxHashMap<_, _>>();
106 Ok((id, items))
107 })
108 .collect::<Cancelable<FxHashMap<_, _>>>()?;
109 106
110 let resolver = Resolver::new(db, &input, source_root, module_tree); 107 let resolver = Resolver::new(db, &input, source_root, module_tree);
111 let res = resolver.resolve()?; 108 let res = resolver.resolve()?;
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 70dd850d7..7ab8eeae2 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -5,7 +5,7 @@
5/// 5///
6/// So, this modules should not be used during hir construction, it exists 6/// So, this modules should not be used during hir construction, it exists
7/// purely for "IDE needs". 7/// purely for "IDE needs".
8use ra_db::{FileId, FilePosition, Cancelable}; 8use ra_db::{FileId, FilePosition};
9use ra_syntax::{ 9use ra_syntax::{
10 SmolStr, TextRange, SyntaxNode, 10 SmolStr, TextRange, SyntaxNode,
11 ast::{self, AstNode, NameOwner}, 11 ast::{self, AstNode, NameOwner},
@@ -18,7 +18,7 @@ use crate::{
18}; 18};
19 19
20/// Locates the module by `FileId`. Picks topmost module in the file. 20/// Locates the module by `FileId`. Picks topmost module in the file.
21pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { 21pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Module> {
22 let module_source = SourceItemId { 22 let module_source = SourceItemId {
23 file_id: file_id.into(), 23 file_id: file_id.into(),
24 item_id: None, 24 item_id: None,
@@ -31,25 +31,22 @@ pub fn module_from_declaration(
31 db: &impl HirDatabase, 31 db: &impl HirDatabase,
32 file_id: FileId, 32 file_id: FileId,
33 decl: &ast::Module, 33 decl: &ast::Module,
34) -> Cancelable<Option<Module>> { 34) -> Option<Module> {
35 let parent_module = module_from_file_id(db, file_id)?; 35 let parent_module = module_from_file_id(db, file_id);
36 let child_name = decl.name(); 36 let child_name = decl.name();
37 match (parent_module, child_name) { 37 match (parent_module, child_name) {
38 (Some(parent_module), Some(child_name)) => { 38 (Some(parent_module), Some(child_name)) => {
39 if let Some(child) = parent_module.child(db, &child_name.as_name())? { 39 if let Some(child) = parent_module.child(db, &child_name.as_name()) {
40 return Ok(Some(child)); 40 return Some(child);
41 } 41 }
42 } 42 }
43 _ => (), 43 _ => (),
44 } 44 }
45 Ok(None) 45 None
46} 46}
47 47
48/// Locates the module by position in the source code. 48/// Locates the module by position in the source code.
49pub fn module_from_position( 49pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> {
50 db: &impl HirDatabase,
51 position: FilePosition,
52) -> Cancelable<Option<Module>> {
53 let file = db.source_file(position.file_id); 50 let file = db.source_file(position.file_id);
54 match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) { 51 match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) {
55 Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), 52 Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m),
@@ -61,7 +58,7 @@ fn module_from_inline(
61 db: &impl HirDatabase, 58 db: &impl HirDatabase,
62 file_id: FileId, 59 file_id: FileId,
63 module: &ast::Module, 60 module: &ast::Module,
64) -> Cancelable<Option<Module>> { 61) -> Option<Module> {
65 assert!(!module.has_semi()); 62 assert!(!module.has_semi());
66 let file_id = file_id.into(); 63 let file_id = file_id.into();
67 let file_items = db.file_items(file_id); 64 let file_items = db.file_items(file_id);
@@ -78,7 +75,7 @@ pub fn module_from_child_node(
78 db: &impl HirDatabase, 75 db: &impl HirDatabase,
79 file_id: FileId, 76 file_id: FileId,
80 child: &SyntaxNode, 77 child: &SyntaxNode,
81) -> Cancelable<Option<Module>> { 78) -> Option<Module> {
82 if let Some(m) = child 79 if let Some(m) = child
83 .ancestors() 80 .ancestors()
84 .filter_map(ast::Module::cast) 81 .filter_map(ast::Module::cast)
@@ -90,22 +87,16 @@ pub fn module_from_child_node(
90 } 87 }
91} 88}
92 89
93fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> { 90fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> {
94 let source_root_id = db.file_source_root(source.file_id.as_original_file()); 91 let source_root_id = db.file_source_root(source.file_id.as_original_file());
95 let module_tree = db.module_tree(source_root_id); 92 let module_tree = db.module_tree(source_root_id);
96 let module_id = ctry!(module_tree.find_module_by_source(source)); 93 let module_id = module_tree.find_module_by_source(source)?;
97 Ok(Some(Module::from_module_id(db, source_root_id, module_id)?)) 94 Some(Module::from_module_id(db, source_root_id, module_id))
98} 95}
99 96
100pub fn function_from_position( 97pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> {
101 db: &impl HirDatabase,
102 position: FilePosition,
103) -> Cancelable<Option<Function>> {
104 let file = db.source_file(position.file_id); 98 let file = db.source_file(position.file_id);
105 let fn_def = ctry!(find_node_at_offset::<ast::FnDef>( 99 let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), position.offset)?;
106 file.syntax(),
107 position.offset
108 ));
109 function_from_source(db, position.file_id, fn_def) 100 function_from_source(db, position.file_id, fn_def)
110} 101}
111 102
@@ -113,10 +104,10 @@ pub fn function_from_source(
113 db: &impl HirDatabase, 104 db: &impl HirDatabase,
114 file_id: FileId, 105 file_id: FileId,
115 fn_def: &ast::FnDef, 106 fn_def: &ast::FnDef,
116) -> Cancelable<Option<Function>> { 107) -> Option<Function> {
117 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); 108 let module = module_from_child_node(db, file_id, fn_def.syntax())?;
118 let res = function_from_module(db, &module, fn_def); 109 let res = function_from_module(db, &module, fn_def);
119 Ok(Some(res)) 110 Some(res)
120} 111}
121 112
122pub fn function_from_module( 113pub fn function_from_module(
@@ -145,21 +136,18 @@ pub fn function_from_child_node(
145 db: &impl HirDatabase, 136 db: &impl HirDatabase,
146 file_id: FileId, 137 file_id: FileId,
147 node: &SyntaxNode, 138 node: &SyntaxNode,
148) -> Cancelable<Option<Function>> { 139) -> Option<Function> {
149 let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); 140 let fn_def = node.ancestors().find_map(ast::FnDef::cast)?;
150 function_from_source(db, file_id, fn_def) 141 function_from_source(db, file_id, fn_def)
151} 142}
152 143
153pub fn macro_symbols( 144pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> {
154 db: &impl HirDatabase, 145 let module = match module_from_file_id(db, file_id) {
155 file_id: FileId,
156) -> Cancelable<Vec<(SmolStr, TextRange)>> {
157 let module = match module_from_file_id(db, file_id)? {
158 Some(it) => it, 146 Some(it) => it,
159 None => return Ok(Vec::new()), 147 None => return Vec::new(),
160 }; 148 };
161 let loc = module.def_id.loc(db); 149 let loc = module.def_id.loc(db);
162 let items = db.input_module_items(loc.source_root_id, loc.module_id)?; 150 let items = db.input_module_items(loc.source_root_id, loc.module_id);
163 let mut res = Vec::new(); 151 let mut res = Vec::new();
164 152
165 for macro_call_id in items 153 for macro_call_id in items
@@ -184,5 +172,5 @@ pub fn macro_symbols(
184 } 172 }
185 } 173 }
186 174
187 Ok(res) 175 res
188} 176}
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 8aacb1a7f..b81d91e80 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -320,9 +320,7 @@ fn infer(content: &str) -> String {
320 .descendants() 320 .descendants()
321 .filter_map(ast::FnDef::cast) 321 .filter_map(ast::FnDef::cast)
322 { 322 {
323 let func = source_binder::function_from_source(&db, file_id, fn_def) 323 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
324 .unwrap()
325 .unwrap();
326 let inference_result = func.infer(&db).unwrap(); 324 let inference_result = func.infer(&db).unwrap();
327 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); 325 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap();
328 let mut types = Vec::new(); 326 let mut types = Vec::new();
@@ -404,9 +402,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
404 } 402 }
405 ", 403 ",
406 ); 404 );
407 let func = source_binder::function_from_position(&db, pos) 405 let func = source_binder::function_from_position(&db, pos).unwrap();
408 .unwrap()
409 .unwrap();
410 { 406 {
411 let events = db.log_executed(|| { 407 let events = db.log_executed(|| {
412 func.infer(&db).unwrap(); 408 func.infer(&db).unwrap();
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index 27b760780..efa320d83 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -20,7 +20,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable
20 let name_ref = ctry!(calling_node.name_ref()); 20 let name_ref = ctry!(calling_node.name_ref());
21 21
22 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 22 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
23 let file_symbols = db.index_resolve(name_ref)?; 23 let file_symbols = db.index_resolve(name_ref);
24 let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF)); 24 let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF));
25 let fn_file = db.source_file(symbol.file_id); 25 let fn_file = db.source_file(symbol.file_id);
26 let fn_def = symbol.ptr.resolve(&fn_file); 26 let fn_def = symbol.ptr.resolve(&fn_file);
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 113f6c070..f5b5ed689 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -42,7 +42,7 @@ impl<'a> CompletionContext<'a> {
42 original_file: &'a SourceFile, 42 original_file: &'a SourceFile,
43 position: FilePosition, 43 position: FilePosition,
44 ) -> Cancelable<Option<CompletionContext<'a>>> { 44 ) -> Cancelable<Option<CompletionContext<'a>>> {
45 let module = source_binder::module_from_position(db, position)?; 45 let module = source_binder::module_from_position(db, position);
46 let leaf = 46 let leaf =
47 ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()); 47 ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased());
48 let mut ctx = CompletionContext { 48 let mut ctx = CompletionContext {
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 332a2fb8d..591f36cce 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -48,7 +48,7 @@ pub(crate) fn reference_definition(
48) -> Cancelable<ReferenceResult> { 48) -> Cancelable<ReferenceResult> {
49 use self::ReferenceResult::*; 49 use self::ReferenceResult::*;
50 if let Some(function) = 50 if let Some(function) =
51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? 51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())
52 { 52 {
53 let scope = function.scopes(db)?; 53 let scope = function.scopes(db)?;
54 // First try to resolve the symbol locally 54 // First try to resolve the symbol locally
@@ -77,8 +77,7 @@ pub(crate) fn reference_definition(
77 } 77 }
78 } 78 }
79 // Then try module name resolution 79 // Then try module name resolution
80 if let Some(module) = 80 if let Some(module) = hir::source_binder::module_from_child_node(db, file_id, name_ref.syntax())
81 hir::source_binder::module_from_child_node(db, file_id, name_ref.syntax())?
82 { 81 {
83 if let Some(path) = name_ref 82 if let Some(path) = name_ref
84 .syntax() 83 .syntax()
@@ -96,7 +95,7 @@ pub(crate) fn reference_definition(
96 } 95 }
97 // If that fails try the index based approach. 96 // If that fails try the index based approach.
98 let navs = db 97 let navs = db
99 .index_resolve(name_ref)? 98 .index_resolve(name_ref)
100 .into_iter() 99 .into_iter()
101 .map(NavigationTarget::from_symbol) 100 .map(NavigationTarget::from_symbol)
102 .collect(); 101 .collect();
@@ -111,7 +110,7 @@ fn name_definition(
111 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 110 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
112 if module.has_semi() { 111 if module.has_semi() {
113 if let Some(child_module) = 112 if let Some(child_module) =
114 hir::source_binder::module_from_declaration(db, file_id, module)? 113 hir::source_binder::module_from_declaration(db, file_id, module)
115 { 114 {
116 let nav = NavigationTarget::from_module(db, child_module)?; 115 let nav = NavigationTarget::from_module(db, child_module)?;
117 return Ok(Some(vec![nav])); 116 return Ok(Some(vec![nav]));
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 107b23833..26f3ced70 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -72,7 +72,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
72 db, 72 db,
73 frange.file_id, 73 frange.file_id,
74 parent_fn 74 parent_fn
75 )?); 75 ));
76 let infer = function.infer(db)?; 76 let infer = function.infer(db)?;
77 let syntax_mapping = function.body_syntax_mapping(db)?; 77 let syntax_mapping = function.body_syntax_mapping(db)?;
78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { 78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index ba4aa0fd5..76cb312dd 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -100,7 +100,7 @@ impl db::RootDatabase {
100impl db::RootDatabase { 100impl db::RootDatabase {
101 /// Returns `Vec` for the same reason as `parent_module` 101 /// Returns `Vec` for the same reason as `parent_module`
102 pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 102 pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
103 let module = match source_binder::module_from_file_id(self, file_id)? { 103 let module = match source_binder::module_from_file_id(self, file_id) {
104 Some(it) => it, 104 Some(it) => it,
105 None => return Ok(Vec::new()), 105 None => return Ok(Vec::new()),
106 }; 106 };
@@ -147,7 +147,7 @@ impl db::RootDatabase {
147 db, 147 db,
148 position.file_id, 148 position.file_id,
149 binding.syntax(), 149 binding.syntax(),
150 )?); 150 ));
151 return Ok(Some((binding, descr))); 151 return Ok(Some((binding, descr)));
152 }; 152 };
153 let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); 153 let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset));
@@ -155,7 +155,7 @@ impl db::RootDatabase {
155 db, 155 db,
156 position.file_id, 156 position.file_id,
157 name_ref.syntax(), 157 name_ref.syntax(),
158 )?); 158 ));
159 let scope = descr.scopes(db)?; 159 let scope = descr.scopes(db)?;
160 let resolved = ctry!(scope.resolve_local_name(name_ref)); 160 let resolved = ctry!(scope.resolve_local_name(name_ref));
161 let resolved = resolved.ptr().resolve(source_file); 161 let resolved = resolved.ptr().resolve(source_file);
@@ -179,7 +179,7 @@ impl db::RootDatabase {
179 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), 179 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
180 }) 180 })
181 .collect::<Vec<_>>(); 181 .collect::<Vec<_>>();
182 if let Some(m) = source_binder::module_from_file_id(self, file_id)? { 182 if let Some(m) = source_binder::module_from_file_id(self, file_id) {
183 for (name_node, problem) in m.problems(self)? { 183 for (name_node, problem) in m.problems(self)? {
184 let source_root = self.file_source_root(file_id); 184 let source_root = self.file_source_root(file_id);
185 let diag = match problem { 185 let diag = match problem {
@@ -258,7 +258,7 @@ impl db::RootDatabase {
258 .collect::<Vec<_>>(); 258 .collect::<Vec<_>>();
259 Ok(res) 259 Ok(res)
260 } 260 }
261 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> { 261 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
262 let name = name_ref.text(); 262 let name = name_ref.text();
263 let mut query = Query::new(name.to_string()); 263 let mut query = Query::new(name.to_string());
264 query.exact(); 264 query.exact();
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index abb50ff95..e0b8410d1 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -381,12 +381,11 @@ impl Analysis {
381 /// Fuzzy searches for a symbol. 381 /// Fuzzy searches for a symbol.
382 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { 382 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
383 self.with_db(|db| { 383 self.with_db(|db| {
384 let res = symbol_index::world_symbols(db, query)? 384 symbol_index::world_symbols(db, query)
385 .into_iter() 385 .into_iter()
386 .map(NavigationTarget::from_symbol) 386 .map(NavigationTarget::from_symbol)
387 .collect::<Vec<_>>(); 387 .collect::<Vec<_>>()
388 Ok(res) 388 })
389 })?
390 } 389 }
391 390
392 pub fn goto_definition( 391 pub fn goto_definition(
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs
index 675042a6c..451304739 100644
--- a/crates/ra_ide_api/src/parent_module.rs
+++ b/crates/ra_ide_api/src/parent_module.rs
@@ -8,7 +8,7 @@ pub(crate) fn parent_module(
8 db: &RootDatabase, 8 db: &RootDatabase,
9 position: FilePosition, 9 position: FilePosition,
10) -> Cancelable<Vec<NavigationTarget>> { 10) -> Cancelable<Vec<NavigationTarget>> {
11 let module = match hir::source_binder::module_from_position(db, position)? { 11 let module = match hir::source_binder::module_from_position(db, position) {
12 None => return Ok(Vec::new()), 12 None => return Ok(Vec::new()),
13 Some(it) => it, 13 Some(it) => it,
14 }; 14 };
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index f1de28094..9fa0f79a6 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -75,8 +75,7 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
75 return None; 75 return None;
76 } 76 }
77 let range = module.syntax().range(); 77 let range = module.syntax().range();
78 let module = 78 let module = hir::source_binder::module_from_child_node(db, file_id, module.syntax())?;
79 hir::source_binder::module_from_child_node(db, file_id, module.syntax()).ok()??;
80 79
81 // FIXME: thread cancellation instead of `.ok`ing 80 // FIXME: thread cancellation instead of `.ok`ing
82 let path = module 81 let path = module
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs
index b7a3a3550..74165d68f 100644
--- a/crates/ra_ide_api/src/symbol_index.rs
+++ b/crates/ra_ide_api/src/symbol_index.rs
@@ -37,13 +37,13 @@ use salsa::ParallelDatabase;
37use rayon::prelude::*; 37use rayon::prelude::*;
38 38
39use crate::{ 39use crate::{
40 Cancelable, FileId, Query, 40 FileId, Query,
41 db::RootDatabase, 41 db::RootDatabase,
42}; 42};
43 43
44salsa::query_group! { 44salsa::query_group! {
45 pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { 45 pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
46 fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { 46 fn file_symbols(file_id: FileId) -> Arc<SymbolIndex> {
47 type FileSymbolsQuery; 47 type FileSymbolsQuery;
48 } 48 }
49 fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> { 49 fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
@@ -53,7 +53,7 @@ salsa::query_group! {
53 } 53 }
54} 54}
55 55
56fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { 56fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> {
57 db.check_canceled(); 57 db.check_canceled();
58 let source_file = db.source_file(file_id); 58 let source_file = db.source_file(file_id);
59 let mut symbols = source_file 59 let mut symbols = source_file
@@ -63,16 +63,16 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<Sy
63 .map(move |(name, ptr)| FileSymbol { name, ptr, file_id }) 63 .map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
64 .collect::<Vec<_>>(); 64 .collect::<Vec<_>>();
65 65
66 for (name, text_range) in hir::source_binder::macro_symbols(db, file_id)? { 66 for (name, text_range) in hir::source_binder::macro_symbols(db, file_id) {
67 let node = find_covering_node(source_file.syntax(), text_range); 67 let node = find_covering_node(source_file.syntax(), text_range);
68 let ptr = LocalSyntaxPtr::new(node); 68 let ptr = LocalSyntaxPtr::new(node);
69 symbols.push(FileSymbol { file_id, name, ptr }) 69 symbols.push(FileSymbol { file_id, name, ptr })
70 } 70 }
71 71
72 Ok(Arc::new(SymbolIndex::new(symbols))) 72 Arc::new(SymbolIndex::new(symbols))
73} 73}
74 74
75pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> { 75pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
76 /// Need to wrap Snapshot to provide `Clone` impl for `map_with` 76 /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
77 struct Snap(salsa::Snapshot<RootDatabase>); 77 struct Snap(salsa::Snapshot<RootDatabase>);
78 impl Clone for Snap { 78 impl Clone for Snap {
@@ -98,10 +98,9 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<F
98 files 98 files
99 .par_iter() 99 .par_iter()
100 .map_with(snap, |db, &file_id| db.0.file_symbols(file_id)) 100 .map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
101 .filter_map(|it| it.ok())
102 .collect() 101 .collect()
103 }; 102 };
104 Ok(query.search(&buf)) 103 query.search(&buf)
105} 104}
106 105
107#[derive(Default, Debug)] 106#[derive(Default, Debug)]