From 9fb41716de095fa365eecedab3427af7b5001644 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Oct 2018 22:09:12 +0300 Subject: [PATCH] make more things cancelable --- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_analysis/src/lib.rs | 27 +++++++++---------- .../ra_lsp_server/src/main_loop/handlers.rs | 12 ++++----- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4cfb681d875..d60fb827817 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -19,7 +19,7 @@ use rustc_hash::FxHashSet; use crate::{ descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, - CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, + CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position, Query, SourceChange, SourceFileEdit, Cancelable, }; diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 7e9798c29ed..8595d7e03af 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -219,19 +219,23 @@ impl Analysis { let file = self.imp.file_syntax(file_id); ra_editor::file_structure(&file) } - pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> { - self.imp.world_symbols(query) + pub fn folding_ranges(&self, file_id: FileId) -> Vec { + let file = self.imp.file_syntax(file_id); + ra_editor::folding_ranges(&file) + } + pub fn symbol_search(&self, query: Query) -> Cancelable> { + Ok(self.imp.world_symbols(query)) } pub fn approximately_resolve_symbol( &self, file_id: FileId, offset: TextUnit - ) -> Vec<(FileId, FileSymbol)> { - self.imp - .approximately_resolve_symbol(file_id, offset) + ) -> Cancelable> { + Ok(self.imp + .approximately_resolve_symbol(file_id, offset)) } - pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Vec<(FileId, TextRange)> { - self.imp.find_all_refs(file_id, offset) + pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable> { + Ok(self.imp.find_all_refs(file_id, offset)) } pub fn parent_module(&self, file_id: FileId) -> Cancelable> { self.imp.parent_module(file_id) @@ -260,17 +264,12 @@ impl Analysis { pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { Ok(self.imp.diagnostics(file_id)) } - pub fn folding_ranges(&self, file_id: FileId) -> Vec { - let file = self.imp.file_syntax(file_id); - ra_editor::folding_ranges(&file) - } - pub fn resolve_callable( &self, file_id: FileId, offset: TextUnit, - ) -> Option<(FnDescriptor, Option)> { - self.imp.resolve_callable(file_id, offset) + ) -> Cancelable)>> { + Ok(self.imp.resolve_callable(file_id, offset)) } } diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 9e76a51c1d4..78a8ccfc523 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( query: Query, ) -> Result> { let mut res = Vec::new(); - for (file_id, symbol) in world.analysis().symbol_search(query) { + for (file_id, symbol) in world.analysis().symbol_search(query)? { let line_index = world.analysis().file_line_index(file_id); let info = SymbolInformation { name: symbol.name.to_string(), @@ -221,7 +221,7 @@ pub fn handle_goto_definition( let mut res = Vec::new(); for (file_id, symbol) in world .analysis() - .approximately_resolve_symbol(file_id, offset) + .approximately_resolve_symbol(file_id, offset)? { let line_index = world.analysis().file_line_index(file_id); let location = to_location(file_id, symbol.node_range, &world, &line_index)?; @@ -435,7 +435,7 @@ pub fn handle_signature_help( let offset = params.position.conv_with(&line_index); if let Some((descriptor, active_param)) = - world.analysis().resolve_callable(file_id, offset) + world.analysis().resolve_callable(file_id, offset)? { let parameters: Vec = descriptor .params @@ -473,7 +473,7 @@ pub fn handle_prepare_rename( // We support renaming references like handle_rename does. // In the future we may want to reject the renaming of things like keywords here too. - let refs = world.analysis().find_all_refs(file_id, offset); + let refs = world.analysis().find_all_refs(file_id, offset)?; if refs.is_empty() { return Ok(None); } @@ -497,7 +497,7 @@ pub fn handle_rename( return Ok(None); } - let refs = world.analysis().find_all_refs(file_id, offset); + let refs = world.analysis().find_all_refs(file_id, offset)?; if refs.is_empty() { return Ok(None); } @@ -530,7 +530,7 @@ pub fn handle_references( let line_index = world.analysis().file_line_index(file_id); let offset = params.position.conv_with(&line_index); - let refs = world.analysis().find_all_refs(file_id, offset); + let refs = world.analysis().find_all_refs(file_id, offset)?; Ok(Some(refs.into_iter() .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())