From 8eea10e3ab25111375a95990b93d1170d5fe8a9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Oct 2018 22:35:55 +0300 Subject: actually check for cancelation --- crates/ra_analysis/src/db.rs | 12 +++++++++++- crates/ra_analysis/src/lib.rs | 8 ++++---- crates/ra_analysis/src/module_map.rs | 7 +++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index d621b3b22..09d74b9e7 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -10,7 +10,8 @@ use rustc_hash::FxHashSet; use salsa; use crate::{ - Cancelable, + db, + Cancelable, Canceled, module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, symbol_index::SymbolIndex, FileId, FileResolverImp, @@ -33,6 +34,14 @@ impl salsa::Database for RootDatabase { } } +pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> { + if db.salsa_runtime().is_current_revision_canceled() { + Err(Canceled) + } else { + Ok(()) + } +} + impl salsa::ParallelDatabase for RootDatabase { fn fork(&self) -> Self { RootDatabase { @@ -115,6 +124,7 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc { Arc::new(LineIndex::new(&*text)) } fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable> { + db::check_canceled(db)?; let syntax = db.file_syntax(file_id); Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) } diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 189dbd9c2..03708d450 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -38,17 +38,17 @@ pub use ra_editor::{ }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct Cancel; +pub struct Canceled; -pub type Cancelable = Result; +pub type Cancelable = Result; -impl std::fmt::Display for Cancel { +impl std::fmt::Display for Canceled { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fmt.write_str("Canceled") } } -impl std::error::Error for Cancel { +impl std::error::Error for Canceled { } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/ra_analysis/src/module_map.rs b/crates/ra_analysis/src/module_map.rs index 0c413becd..3c800265a 100644 --- a/crates/ra_analysis/src/module_map.rs +++ b/crates/ra_analysis/src/module_map.rs @@ -1,12 +1,13 @@ +use std::sync::Arc; + use crate::{ + db, Cancelable, db::SyntaxDatabase, descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, FileId, }; -use std::sync::Arc; - salsa::query_group! { pub(crate) trait ModulesDatabase: SyntaxDatabase { fn module_tree() -> Cancelable> { @@ -19,11 +20,13 @@ salsa::query_group! { } fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable> { + db::check_canceled(db)?; let file = db.file_syntax(file_id); Ok(Arc::new(ModuleDescriptor::new(file.ast()))) } fn module_tree(db: &impl ModulesDatabase) -> Cancelable> { + db::check_canceled(db)?; let file_set = db.file_set(); let mut files = Vec::new(); for &file_id in file_set.files.iter() { -- cgit v1.2.3