check_canceled is a method

This commit is contained in:
Aleksey Kladov 2018-11-28 01:38:39 +03:00
parent 806ea03b64
commit 4c9933c016
4 changed files with 9 additions and 15 deletions

View File

@ -6,7 +6,6 @@ use ra_syntax::{SourceFileNode, SyntaxNode};
use salsa::{self, Database};
use crate::{
db,
hir,
symbol_index::SymbolIndex,
syntax_ptr::SyntaxPtr,
@ -59,14 +58,6 @@ impl Default 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 snapshot(&self) -> salsa::Snapshot<RootDatabase> {
salsa::Snapshot::new(RootDatabase {
@ -80,7 +71,11 @@ impl salsa::ParallelDatabase for RootDatabase {
pub(crate) trait BaseDatabase: salsa::Database {
fn id_maps(&self) -> &IdMaps;
fn check_canceled(&self) -> Cancelable<()> {
check_canceled(self)
if self.salsa_runtime().is_current_revision_canceled() {
Err(Canceled)
} else {
Ok(())
}
}
}
@ -171,7 +166,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)?;
db.check_canceled()?;
let syntax = db.file_syntax(file_id);
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
}

View File

@ -8,7 +8,6 @@ use relative_path::RelativePathBuf;
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
db,
hir::HirDatabase,
input::{SourceRoot, SourceRootId},
Cancelable, FileId, FileResolverImp,
@ -52,7 +51,7 @@ pub(crate) fn module_tree(
db: &impl HirDatabase,
source_root: SourceRootId,
) -> Cancelable<Arc<ModuleTree>> {
db::check_canceled(db)?;
db.check_canceled()?;
let res = create_module_tree(db, source_root)?;
Ok(Arc::new(res))
}

View File

@ -248,7 +248,7 @@ where
}
for &module_id in self.input.keys() {
crate::db::check_canceled(self.db)?;
self.db.check_canceled()?;
self.resolve_imports(module_id);
}
Ok(self.result)

View File

@ -33,7 +33,7 @@ impl CrateGraph {
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
fn file_stem(&self, file_id: FileId) -> String;
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
fn debug_path(&self, _file_id: FileId) -> Option<std::path::PathBuf> {
fn debug_path(&self, _1file_id: FileId) -> Option<std::path::PathBuf> {
None
}
}