diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 15:19:40 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 15:19:40 +0000 |
commit | 91feed736f91a3790b2f5a5d0d879c06843bce95 (patch) | |
tree | 6a71bcb433b82e4c473238d439aad2ef76144157 /crates/ra_ide_api | |
parent | a36b2cf377a90cf13bb097e57878b8384d30c53a (diff) | |
parent | fb012e5c1e49af73b480127bcf56d8f5993b8032 (diff) |
Merge #550
550: remove Cancelable from source binders r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/imp.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/runnables.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/symbol_index.rs | 15 |
9 files changed, 24 insertions, 28 deletions
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 { | |||
100 | impl db::RootDatabase { | 100 | impl 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; | |||
37 | use rayon::prelude::*; | 37 | use rayon::prelude::*; |
38 | 38 | ||
39 | use crate::{ | 39 | use crate::{ |
40 | Cancelable, FileId, Query, | 40 | FileId, Query, |
41 | db::RootDatabase, | 41 | db::RootDatabase, |
42 | }; | 42 | }; |
43 | 43 | ||
44 | salsa::query_group! { | 44 | salsa::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 | ||
56 | fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { | 56 | fn 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 | ||
75 | pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> { | 75 | pub(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)] |