aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-20 20:35:55 +0100
committerAleksey Kladov <[email protected]>2018-10-20 20:35:55 +0100
commit8eea10e3ab25111375a95990b93d1170d5fe8a9f (patch)
tree469ec771c1e1d3608518557f05d175703dec85d9
parent71cbdddf1c6b6c34c05aea01b92bb8a105b32c71 (diff)
actually check for cancelation
-rw-r--r--crates/ra_analysis/src/db.rs12
-rw-r--r--crates/ra_analysis/src/lib.rs8
-rw-r--r--crates/ra_analysis/src/module_map.rs7
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;
10use salsa; 10use salsa;
11 11
12use crate::{ 12use crate::{
13 Cancelable, 13 db,
14 Cancelable, Canceled,
14 module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, 15 module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase},
15 symbol_index::SymbolIndex, 16 symbol_index::SymbolIndex,
16 FileId, FileResolverImp, 17 FileId, FileResolverImp,
@@ -33,6 +34,14 @@ impl salsa::Database for RootDatabase {
33 } 34 }
34} 35}
35 36
37pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
38 if db.salsa_runtime().is_current_revision_canceled() {
39 Err(Canceled)
40 } else {
41 Ok(())
42 }
43}
44
36impl salsa::ParallelDatabase for RootDatabase { 45impl salsa::ParallelDatabase for RootDatabase {
37 fn fork(&self) -> Self { 46 fn fork(&self) -> Self {
38 RootDatabase { 47 RootDatabase {
@@ -115,6 +124,7 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
115 Arc::new(LineIndex::new(&*text)) 124 Arc::new(LineIndex::new(&*text))
116} 125}
117fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { 126fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
127 db::check_canceled(db)?;
118 let syntax = db.file_syntax(file_id); 128 let syntax = db.file_syntax(file_id);
119 Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) 129 Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
120} 130}
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::{
38}; 38};
39 39
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub struct Cancel; 41pub struct Canceled;
42 42
43pub type Cancelable<T> = Result<T, Cancel>; 43pub type Cancelable<T> = Result<T, Canceled>;
44 44
45impl std::fmt::Display for Cancel { 45impl std::fmt::Display for Canceled {
46 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 46 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 fmt.write_str("Canceled") 47 fmt.write_str("Canceled")
48 } 48 }
49} 49}
50 50
51impl std::error::Error for Cancel { 51impl std::error::Error for Canceled {
52} 52}
53 53
54#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 54#[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 @@
1use std::sync::Arc;
2
1use crate::{ 3use crate::{
4 db,
2 Cancelable, 5 Cancelable,
3 db::SyntaxDatabase, 6 db::SyntaxDatabase,
4 descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, 7 descriptors::{ModuleDescriptor, ModuleTreeDescriptor},
5 FileId, 8 FileId,
6}; 9};
7 10
8use std::sync::Arc;
9
10salsa::query_group! { 11salsa::query_group! {
11 pub(crate) trait ModulesDatabase: SyntaxDatabase { 12 pub(crate) trait ModulesDatabase: SyntaxDatabase {
12 fn module_tree() -> Cancelable<Arc<ModuleTreeDescriptor>> { 13 fn module_tree() -> Cancelable<Arc<ModuleTreeDescriptor>> {
@@ -19,11 +20,13 @@ salsa::query_group! {
19} 20}
20 21
21fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> { 22fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
23 db::check_canceled(db)?;
22 let file = db.file_syntax(file_id); 24 let file = db.file_syntax(file_id);
23 Ok(Arc::new(ModuleDescriptor::new(file.ast()))) 25 Ok(Arc::new(ModuleDescriptor::new(file.ast())))
24} 26}
25 27
26fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> { 28fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> {
29 db::check_canceled(db)?;
27 let file_set = db.file_set(); 30 let file_set = db.file_set();
28 let mut files = Vec::new(); 31 let mut files = Vec::new();
29 for &file_id in file_set.files.iter() { 32 for &file_id in file_set.files.iter() {