diff options
Diffstat (limited to 'crates/ra_analysis/src/db.rs')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 99d40a269..956cbe162 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -1,22 +1,25 @@ | |||
1 | use crate::{ | 1 | use std::{ |
2 | module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, | 2 | fmt, |
3 | symbol_index::SymbolIndex, | 3 | hash::{Hash, Hasher}, |
4 | FileId, FileResolverImp, | 4 | sync::Arc, |
5 | }; | 5 | }; |
6 | |||
6 | use ra_editor::LineIndex; | 7 | use ra_editor::LineIndex; |
7 | use ra_syntax::File; | 8 | use ra_syntax::File; |
8 | use rustc_hash::FxHashSet; | 9 | use rustc_hash::FxHashSet; |
9 | use salsa; | 10 | use salsa; |
10 | 11 | ||
11 | use std::{ | 12 | use crate::{ |
12 | fmt, | 13 | db, |
13 | hash::{Hash, Hasher}, | 14 | Cancelable, Canceled, |
14 | sync::Arc, | 15 | module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, |
16 | symbol_index::SymbolIndex, | ||
17 | FileId, FileResolverImp, | ||
15 | }; | 18 | }; |
16 | 19 | ||
17 | #[derive(Default)] | 20 | #[derive(Default)] |
18 | pub(crate) struct RootDatabase { | 21 | pub(crate) struct RootDatabase { |
19 | runtime: salsa::runtime::Runtime<RootDatabase>, | 22 | runtime: salsa::Runtime<RootDatabase>, |
20 | } | 23 | } |
21 | 24 | ||
22 | impl fmt::Debug for RootDatabase { | 25 | impl fmt::Debug for RootDatabase { |
@@ -26,11 +29,19 @@ impl fmt::Debug for RootDatabase { | |||
26 | } | 29 | } |
27 | 30 | ||
28 | impl salsa::Database for RootDatabase { | 31 | impl salsa::Database for RootDatabase { |
29 | fn salsa_runtime(&self) -> &salsa::runtime::Runtime<RootDatabase> { | 32 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
30 | &self.runtime | 33 | &self.runtime |
31 | } | 34 | } |
32 | } | 35 | } |
33 | 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 | |||
34 | impl salsa::ParallelDatabase for RootDatabase { | 45 | impl salsa::ParallelDatabase for RootDatabase { |
35 | fn fork(&self) -> Self { | 46 | fn fork(&self) -> Self { |
36 | RootDatabase { | 47 | RootDatabase { |
@@ -69,7 +80,7 @@ salsa::query_group! { | |||
69 | type FileTextQuery; | 80 | type FileTextQuery; |
70 | storage input; | 81 | storage input; |
71 | } | 82 | } |
72 | fn file_set(key: ()) -> Arc<FileSet> { | 83 | fn file_set() -> Arc<FileSet> { |
73 | type FileSetQuery; | 84 | type FileSetQuery; |
74 | storage input; | 85 | storage input; |
75 | } | 86 | } |
@@ -104,7 +115,7 @@ salsa::query_group! { | |||
104 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { | 115 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { |
105 | type FileLinesQuery; | 116 | type FileLinesQuery; |
106 | } | 117 | } |
107 | fn file_symbols(file_id: FileId) -> Arc<SymbolIndex> { | 118 | fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { |
108 | type FileSymbolsQuery; | 119 | type FileSymbolsQuery; |
109 | } | 120 | } |
110 | } | 121 | } |
@@ -118,7 +129,8 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | |||
118 | let text = db.file_text(file_id); | 129 | let text = db.file_text(file_id); |
119 | Arc::new(LineIndex::new(&*text)) | 130 | Arc::new(LineIndex::new(&*text)) |
120 | } | 131 | } |
121 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<SymbolIndex> { | 132 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { |
133 | db::check_canceled(db)?; | ||
122 | let syntax = db.file_syntax(file_id); | 134 | let syntax = db.file_syntax(file_id); |
123 | Arc::new(SymbolIndex::for_file(file_id, syntax)) | 135 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) |
124 | } | 136 | } |