actually check for cancelation
This commit is contained in:
parent
71cbdddf1c
commit
8eea10e3ab
@ -10,7 +10,8 @@
|
|||||||
use salsa;
|
use salsa;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Cancelable,
|
db,
|
||||||
|
Cancelable, Canceled,
|
||||||
module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase},
|
module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase},
|
||||||
symbol_index::SymbolIndex,
|
symbol_index::SymbolIndex,
|
||||||
FileId, FileResolverImp,
|
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 {
|
impl salsa::ParallelDatabase for RootDatabase {
|
||||||
fn fork(&self) -> Self {
|
fn fork(&self) -> Self {
|
||||||
RootDatabase {
|
RootDatabase {
|
||||||
@ -115,6 +124,7 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
|
|||||||
Arc::new(LineIndex::new(&*text))
|
Arc::new(LineIndex::new(&*text))
|
||||||
}
|
}
|
||||||
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||||
|
db::check_canceled(db)?;
|
||||||
let syntax = db.file_syntax(file_id);
|
let syntax = db.file_syntax(file_id);
|
||||||
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,17 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[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 {
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
fmt.write_str("Canceled")
|
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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
db,
|
||||||
Cancelable,
|
Cancelable,
|
||||||
db::SyntaxDatabase,
|
db::SyntaxDatabase,
|
||||||
descriptors::{ModuleDescriptor, ModuleTreeDescriptor},
|
descriptors::{ModuleDescriptor, ModuleTreeDescriptor},
|
||||||
FileId,
|
FileId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
pub(crate) trait ModulesDatabase: SyntaxDatabase {
|
pub(crate) trait ModulesDatabase: SyntaxDatabase {
|
||||||
fn module_tree() -> Cancelable<Arc<ModuleTreeDescriptor>> {
|
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>> {
|
fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
|
||||||
|
db::check_canceled(db)?;
|
||||||
let file = db.file_syntax(file_id);
|
let file = db.file_syntax(file_id);
|
||||||
Ok(Arc::new(ModuleDescriptor::new(file.ast())))
|
Ok(Arc::new(ModuleDescriptor::new(file.ast())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> {
|
fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> {
|
||||||
|
db::check_canceled(db)?;
|
||||||
let file_set = db.file_set();
|
let file_set = db.file_set();
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
for &file_id in file_set.files.iter() {
|
for &file_id in file_set.files.iter() {
|
||||||
|
Loading…
Reference in New Issue
Block a user