From c4b0d3cd56ab68f4fa23f7c1f6c76f7f6148153e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Oct 2018 21:52:49 +0300 Subject: make parent module cancelable --- crates/ra_analysis/src/imp.rs | 9 +++++---- crates/ra_analysis/src/lib.rs | 11 ++++++++++- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index a67b1717a..3a135ef13 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -20,7 +20,7 @@ use crate::{ descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, - Query, SourceChange, SourceFileEdit, + Query, SourceChange, SourceFileEdit, Cancelable, }; #[derive(Clone, Debug)] @@ -157,10 +157,10 @@ impl AnalysisImpl { } query.search(&buf, token) } - pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { + pub fn parent_module(&self, file_id: FileId) -> Cancelable> { let root = self.root(file_id); let module_tree = root.module_tree(); - module_tree + let res = module_tree .parent_modules(file_id) .iter() .map(|link| { @@ -174,7 +174,8 @@ impl AnalysisImpl { }; (file_id, sym) }) - .collect() + .collect(); + Ok(res) } pub fn crate_for(&self, file_id: FileId) -> Vec { let module_tree = self.root(file_id).module_tree(); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index b1d5c4936..988a45b46 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -42,6 +42,15 @@ pub struct Cancel; pub type Cancelable = Result; +impl std::fmt::Display for Cancel { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fmt.write_str("Canceled") + } +} + +impl std::error::Error for Cancel { +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FileId(pub u32); @@ -225,7 +234,7 @@ impl Analysis { pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> { self.imp.find_all_refs(file_id, offset, token) } - pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { + pub fn parent_module(&self, file_id: FileId) -> Cancelable> { self.imp.parent_module(file_id) } pub fn crate_for(&self, file_id: FileId) -> Vec { diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 639fe4553..b0b983d0c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -238,7 +238,7 @@ pub fn handle_parent_module( ) -> Result> { let file_id = params.try_conv_with(&world)?; let mut res = Vec::new(); - for (file_id, symbol) in world.analysis().parent_module(file_id) { + for (file_id, symbol) in world.analysis().parent_module(file_id)? { let line_index = world.analysis().file_line_index(file_id); let location = to_location(file_id, symbol.node_range, &world, &line_index)?; res.push(location); -- cgit v1.2.3