diff options
Diffstat (limited to 'crates/ra_ide_db/src/lib.rs')
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index a808de4f1..6900cac73 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -11,11 +11,11 @@ pub mod imports_locator; | |||
11 | pub mod source_change; | 11 | pub mod source_change; |
12 | mod wasm_shims; | 12 | mod wasm_shims; |
13 | 13 | ||
14 | use std::sync::Arc; | 14 | use std::{fmt, sync::Arc}; |
15 | 15 | ||
16 | use hir::db::{AstDatabase, DefDatabase}; | 16 | use hir::db::{AstDatabase, DefDatabase, HirDatabase}; |
17 | use ra_db::{ | 17 | use ra_db::{ |
18 | salsa::{self, Database, Durability}, | 18 | salsa::{self, Durability}, |
19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, | 19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, |
20 | Upcast, | 20 | Upcast, |
21 | }; | 21 | }; |
@@ -33,13 +33,18 @@ use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; | |||
33 | hir::db::DefDatabaseStorage, | 33 | hir::db::DefDatabaseStorage, |
34 | hir::db::HirDatabaseStorage | 34 | hir::db::HirDatabaseStorage |
35 | )] | 35 | )] |
36 | #[derive(Debug)] | ||
37 | pub struct RootDatabase { | 36 | pub struct RootDatabase { |
38 | runtime: salsa::Runtime<RootDatabase>, | 37 | storage: salsa::Storage<RootDatabase>, |
39 | pub last_gc: crate::wasm_shims::Instant, | 38 | pub last_gc: crate::wasm_shims::Instant, |
40 | pub last_gc_check: crate::wasm_shims::Instant, | 39 | pub last_gc_check: crate::wasm_shims::Instant, |
41 | } | 40 | } |
42 | 41 | ||
42 | impl fmt::Debug for RootDatabase { | ||
43 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
44 | f.debug_struct("RootDatabase").finish() | ||
45 | } | ||
46 | } | ||
47 | |||
43 | impl Upcast<dyn AstDatabase> for RootDatabase { | 48 | impl Upcast<dyn AstDatabase> for RootDatabase { |
44 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { | 49 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { |
45 | &*self | 50 | &*self |
@@ -52,6 +57,12 @@ impl Upcast<dyn DefDatabase> for RootDatabase { | |||
52 | } | 57 | } |
53 | } | 58 | } |
54 | 59 | ||
60 | impl Upcast<dyn HirDatabase> for RootDatabase { | ||
61 | fn upcast(&self) -> &(dyn HirDatabase + 'static) { | ||
62 | &*self | ||
63 | } | ||
64 | } | ||
65 | |||
55 | impl FileLoader for RootDatabase { | 66 | impl FileLoader for RootDatabase { |
56 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 67 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
57 | FileLoaderDelegate(self).file_text(file_id) | 68 | FileLoaderDelegate(self).file_text(file_id) |
@@ -65,17 +76,11 @@ impl FileLoader for RootDatabase { | |||
65 | } | 76 | } |
66 | 77 | ||
67 | impl salsa::Database for RootDatabase { | 78 | impl salsa::Database for RootDatabase { |
68 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | ||
69 | &self.runtime | ||
70 | } | ||
71 | fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> { | ||
72 | &mut self.runtime | ||
73 | } | ||
74 | fn on_propagated_panic(&self) -> ! { | 79 | fn on_propagated_panic(&self) -> ! { |
75 | Canceled::throw() | 80 | Canceled::throw() |
76 | } | 81 | } |
77 | fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) { | 82 | fn salsa_event(&self, event: salsa::Event) { |
78 | match event().kind { | 83 | match event.kind { |
79 | salsa::EventKind::DidValidateMemoizedValue { .. } | 84 | salsa::EventKind::DidValidateMemoizedValue { .. } |
80 | | salsa::EventKind::WillExecute { .. } => { | 85 | | salsa::EventKind::WillExecute { .. } => { |
81 | self.check_canceled(); | 86 | self.check_canceled(); |
@@ -94,7 +99,7 @@ impl Default for RootDatabase { | |||
94 | impl RootDatabase { | 99 | impl RootDatabase { |
95 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { | 100 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { |
96 | let mut db = RootDatabase { | 101 | let mut db = RootDatabase { |
97 | runtime: salsa::Runtime::default(), | 102 | storage: salsa::Storage::default(), |
98 | last_gc: crate::wasm_shims::Instant::now(), | 103 | last_gc: crate::wasm_shims::Instant::now(), |
99 | last_gc_check: crate::wasm_shims::Instant::now(), | 104 | last_gc_check: crate::wasm_shims::Instant::now(), |
100 | }; | 105 | }; |
@@ -107,16 +112,16 @@ impl RootDatabase { | |||
107 | 112 | ||
108 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 113 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
109 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | 114 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); |
110 | self.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | 115 | ra_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
111 | self.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | 116 | hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
112 | self.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); | 117 | hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
113 | } | 118 | } |
114 | } | 119 | } |
115 | 120 | ||
116 | impl salsa::ParallelDatabase for RootDatabase { | 121 | impl salsa::ParallelDatabase for RootDatabase { |
117 | fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { | 122 | fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { |
118 | salsa::Snapshot::new(RootDatabase { | 123 | salsa::Snapshot::new(RootDatabase { |
119 | runtime: self.runtime.snapshot(self), | 124 | storage: self.storage.snapshot(), |
120 | last_gc: self.last_gc, | 125 | last_gc: self.last_gc, |
121 | last_gc_check: self.last_gc_check, | 126 | last_gc_check: self.last_gc_check, |
122 | }) | 127 | }) |
@@ -128,7 +133,7 @@ pub trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { | |||
128 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; | 133 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; |
129 | } | 134 | } |
130 | 135 | ||
131 | fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | 136 | fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { |
132 | let text = db.file_text(file_id); | 137 | let text = db.file_text(file_id); |
133 | Arc::new(LineIndex::new(&*text)) | 138 | Arc::new(LineIndex::new(&*text)) |
134 | } | 139 | } |