actually check for cancelation

This commit is contained in:
Aleksey Kladov 2018-10-20 22:35:55 +03:00
parent 71cbdddf1c
commit 8eea10e3ab
3 changed files with 20 additions and 7 deletions

View File

@ -10,7 +10,8 @@
use salsa;
use crate::{
Cancelable,
db,
Cancelable, Canceled,
module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase},
symbol_index::SymbolIndex,
FileId, FileResolverImp,
@ -33,6 +34,14 @@ fn salsa_runtime(&self) -> &salsa::Runtime<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<LineIndex> {
Arc::new(LineIndex::new(&*text))
}
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
db::check_canceled(db)?;
let syntax = db.file_syntax(file_id);
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
}

View File

@ -38,17 +38,17 @@
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Cancel;
pub struct Canceled;
pub type Cancelable<T> = Result<T, Cancel>;
pub type Cancelable<T> = Result<T, Canceled>;
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)]

View File

@ -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<Arc<ModuleTreeDescriptor>> {
@ -19,11 +20,13 @@ fn module_descriptor(file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
}
fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
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<Arc<ModuleTreeDescriptor>> {
db::check_canceled(db)?;
let file_set = db.file_set();
let mut files = Vec::new();
for &file_id in file_set.files.iter() {