diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 8 | ||||
-rw-r--r-- | 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; | |||
10 | use salsa; | 10 | use salsa; |
11 | 11 | ||
12 | use crate::{ | 12 | use 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 | ||
37 | pub(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 | |||
36 | impl salsa::ParallelDatabase for RootDatabase { | 45 | impl 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 | } |
117 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { | 126 | fn 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)] |
41 | pub struct Cancel; | 41 | pub struct Canceled; |
42 | 42 | ||
43 | pub type Cancelable<T> = Result<T, Cancel>; | 43 | pub type Cancelable<T> = Result<T, Canceled>; |
44 | 44 | ||
45 | impl std::fmt::Display for Cancel { | 45 | impl 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 | ||
51 | impl std::error::Error for Cancel { | 51 | impl 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 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
1 | use crate::{ | 3 | use 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 | ||
8 | use std::sync::Arc; | ||
9 | |||
10 | salsa::query_group! { | 11 | salsa::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 | ||
21 | fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> { | 22 | fn 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 | ||
26 | fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> { | 28 | fn 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() { |