aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-20 20:09:12 +0100
committerAleksey Kladov <[email protected]>2018-10-20 20:09:12 +0100
commit9fb41716de095fa365eecedab3427af7b5001644 (patch)
tree05b2d6bc6e02e493f39509a9c46d36564aef270b /crates
parent998f2ae7627053a9363a05a1ab79359882dce39f (diff)
make more things cancelable
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/imp.rs2
-rw-r--r--crates/ra_analysis/src/lib.rs27
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs12
3 files changed, 20 insertions, 21 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 4cfb681d8..d60fb8278 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -19,7 +19,7 @@ use rustc_hash::FxHashSet;
19use crate::{ 19use crate::{
20 descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, 20 descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem},
21 roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, 21 roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
22 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, 22 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
23 Query, SourceChange, SourceFileEdit, Cancelable, 23 Query, SourceChange, SourceFileEdit, Cancelable,
24}; 24};
25 25
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 7e9798c29..8595d7e03 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -219,19 +219,23 @@ impl Analysis {
219 let file = self.imp.file_syntax(file_id); 219 let file = self.imp.file_syntax(file_id);
220 ra_editor::file_structure(&file) 220 ra_editor::file_structure(&file)
221 } 221 }
222 pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> { 222 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
223 self.imp.world_symbols(query) 223 let file = self.imp.file_syntax(file_id);
224 ra_editor::folding_ranges(&file)
225 }
226 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
227 Ok(self.imp.world_symbols(query))
224 } 228 }
225 pub fn approximately_resolve_symbol( 229 pub fn approximately_resolve_symbol(
226 &self, 230 &self,
227 file_id: FileId, 231 file_id: FileId,
228 offset: TextUnit 232 offset: TextUnit
229 ) -> Vec<(FileId, FileSymbol)> { 233 ) -> Cancelable<Vec<(FileId, FileSymbol)>> {
230 self.imp 234 Ok(self.imp
231 .approximately_resolve_symbol(file_id, offset) 235 .approximately_resolve_symbol(file_id, offset))
232 } 236 }
233 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Vec<(FileId, TextRange)> { 237 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable<Vec<(FileId, TextRange)>> {
234 self.imp.find_all_refs(file_id, offset) 238 Ok(self.imp.find_all_refs(file_id, offset))
235 } 239 }
236 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 240 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
237 self.imp.parent_module(file_id) 241 self.imp.parent_module(file_id)
@@ -260,17 +264,12 @@ impl Analysis {
260 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 264 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
261 Ok(self.imp.diagnostics(file_id)) 265 Ok(self.imp.diagnostics(file_id))
262 } 266 }
263 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
264 let file = self.imp.file_syntax(file_id);
265 ra_editor::folding_ranges(&file)
266 }
267
268 pub fn resolve_callable( 267 pub fn resolve_callable(
269 &self, 268 &self,
270 file_id: FileId, 269 file_id: FileId,
271 offset: TextUnit, 270 offset: TextUnit,
272 ) -> Option<(FnDescriptor, Option<usize>)> { 271 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
273 self.imp.resolve_callable(file_id, offset) 272 Ok(self.imp.resolve_callable(file_id, offset))
274 } 273 }
275} 274}
276 275
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 9e76a51c1..78a8ccfc5 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -195,7 +195,7 @@ pub fn handle_workspace_symbol(
195 query: Query, 195 query: Query,
196 ) -> Result<Vec<SymbolInformation>> { 196 ) -> Result<Vec<SymbolInformation>> {
197 let mut res = Vec::new(); 197 let mut res = Vec::new();
198 for (file_id, symbol) in world.analysis().symbol_search(query) { 198 for (file_id, symbol) in world.analysis().symbol_search(query)? {
199 let line_index = world.analysis().file_line_index(file_id); 199 let line_index = world.analysis().file_line_index(file_id);
200 let info = SymbolInformation { 200 let info = SymbolInformation {
201 name: symbol.name.to_string(), 201 name: symbol.name.to_string(),
@@ -221,7 +221,7 @@ pub fn handle_goto_definition(
221 let mut res = Vec::new(); 221 let mut res = Vec::new();
222 for (file_id, symbol) in world 222 for (file_id, symbol) in world
223 .analysis() 223 .analysis()
224 .approximately_resolve_symbol(file_id, offset) 224 .approximately_resolve_symbol(file_id, offset)?
225 { 225 {
226 let line_index = world.analysis().file_line_index(file_id); 226 let line_index = world.analysis().file_line_index(file_id);
227 let location = to_location(file_id, symbol.node_range, &world, &line_index)?; 227 let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
@@ -435,7 +435,7 @@ pub fn handle_signature_help(
435 let offset = params.position.conv_with(&line_index); 435 let offset = params.position.conv_with(&line_index);
436 436
437 if let Some((descriptor, active_param)) = 437 if let Some((descriptor, active_param)) =
438 world.analysis().resolve_callable(file_id, offset) 438 world.analysis().resolve_callable(file_id, offset)?
439 { 439 {
440 let parameters: Vec<ParameterInformation> = descriptor 440 let parameters: Vec<ParameterInformation> = descriptor
441 .params 441 .params
@@ -473,7 +473,7 @@ pub fn handle_prepare_rename(
473 473
474 // We support renaming references like handle_rename does. 474 // We support renaming references like handle_rename does.
475 // In the future we may want to reject the renaming of things like keywords here too. 475 // In the future we may want to reject the renaming of things like keywords here too.
476 let refs = world.analysis().find_all_refs(file_id, offset); 476 let refs = world.analysis().find_all_refs(file_id, offset)?;
477 if refs.is_empty() { 477 if refs.is_empty() {
478 return Ok(None); 478 return Ok(None);
479 } 479 }
@@ -497,7 +497,7 @@ pub fn handle_rename(
497 return Ok(None); 497 return Ok(None);
498 } 498 }
499 499
500 let refs = world.analysis().find_all_refs(file_id, offset); 500 let refs = world.analysis().find_all_refs(file_id, offset)?;
501 if refs.is_empty() { 501 if refs.is_empty() {
502 return Ok(None); 502 return Ok(None);
503 } 503 }
@@ -530,7 +530,7 @@ pub fn handle_references(
530 let line_index = world.analysis().file_line_index(file_id); 530 let line_index = world.analysis().file_line_index(file_id);
531 let offset = params.position.conv_with(&line_index); 531 let offset = params.position.conv_with(&line_index);
532 532
533 let refs = world.analysis().find_all_refs(file_id, offset); 533 let refs = world.analysis().find_all_refs(file_id, offset)?;
534 534
535 Ok(Some(refs.into_iter() 535 Ok(Some(refs.into_iter()
536 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()) 536 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())