diff options
author | Aleksey Kladov <[email protected]> | 2020-02-06 11:43:56 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-06 11:43:56 +0000 |
commit | 939f05f3e33e9f00d5205d60af3a862ae4d58bd6 (patch) | |
tree | 5de7e04d907c8e1cb0e101529abaad3d6f7beba3 /crates/ra_ide/src/ide_db/mod.rs | |
parent | 1bfb111cf9ab938a8795f1ad2089cdd8b8c4b7a5 (diff) |
Move to a crate
Diffstat (limited to 'crates/ra_ide/src/ide_db/mod.rs')
-rw-r--r-- | crates/ra_ide/src/ide_db/mod.rs | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/crates/ra_ide/src/ide_db/mod.rs b/crates/ra_ide/src/ide_db/mod.rs deleted file mode 100644 index 0df4d510f..000000000 --- a/crates/ra_ide/src/ide_db/mod.rs +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | pub mod line_index; | ||
4 | pub mod line_index_utils; | ||
5 | pub mod feature_flags; | ||
6 | pub mod symbol_index; | ||
7 | pub mod change; | ||
8 | |||
9 | use std::sync::Arc; | ||
10 | |||
11 | use ra_db::{ | ||
12 | salsa::{self, Database, Durability}, | ||
13 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, | ||
14 | SourceDatabase, SourceRootId, | ||
15 | }; | ||
16 | use rustc_hash::FxHashMap; | ||
17 | |||
18 | use crate::ide_db::{ | ||
19 | feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase, | ||
20 | }; | ||
21 | |||
22 | #[salsa::database( | ||
23 | ra_db::SourceDatabaseStorage, | ||
24 | ra_db::SourceDatabaseExtStorage, | ||
25 | LineIndexDatabaseStorage, | ||
26 | symbol_index::SymbolsDatabaseStorage, | ||
27 | hir::db::InternDatabaseStorage, | ||
28 | hir::db::AstDatabaseStorage, | ||
29 | hir::db::DefDatabaseStorage, | ||
30 | hir::db::HirDatabaseStorage | ||
31 | )] | ||
32 | #[derive(Debug)] | ||
33 | pub(crate) struct RootDatabase { | ||
34 | runtime: salsa::Runtime<RootDatabase>, | ||
35 | pub(crate) feature_flags: Arc<FeatureFlags>, | ||
36 | pub(crate) debug_data: Arc<DebugData>, | ||
37 | pub(crate) last_gc: crate::wasm_shims::Instant, | ||
38 | pub(crate) last_gc_check: crate::wasm_shims::Instant, | ||
39 | } | ||
40 | |||
41 | impl FileLoader for RootDatabase { | ||
42 | fn file_text(&self, file_id: FileId) -> Arc<String> { | ||
43 | FileLoaderDelegate(self).file_text(file_id) | ||
44 | } | ||
45 | fn resolve_relative_path( | ||
46 | &self, | ||
47 | anchor: FileId, | ||
48 | relative_path: &RelativePath, | ||
49 | ) -> Option<FileId> { | ||
50 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
51 | } | ||
52 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | ||
53 | FileLoaderDelegate(self).relevant_crates(file_id) | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl salsa::Database for RootDatabase { | ||
58 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | ||
59 | &self.runtime | ||
60 | } | ||
61 | fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> { | ||
62 | &mut self.runtime | ||
63 | } | ||
64 | fn on_propagated_panic(&self) -> ! { | ||
65 | Canceled::throw() | ||
66 | } | ||
67 | fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) { | ||
68 | match event().kind { | ||
69 | salsa::EventKind::DidValidateMemoizedValue { .. } | ||
70 | | salsa::EventKind::WillExecute { .. } => { | ||
71 | self.check_canceled(); | ||
72 | } | ||
73 | _ => (), | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | impl Default for RootDatabase { | ||
79 | fn default() -> RootDatabase { | ||
80 | RootDatabase::new(None, FeatureFlags::default()) | ||
81 | } | ||
82 | } | ||
83 | |||
84 | impl RootDatabase { | ||
85 | pub fn new(lru_capacity: Option<usize>, feature_flags: FeatureFlags) -> RootDatabase { | ||
86 | let mut db = RootDatabase { | ||
87 | runtime: salsa::Runtime::default(), | ||
88 | last_gc: crate::wasm_shims::Instant::now(), | ||
89 | last_gc_check: crate::wasm_shims::Instant::now(), | ||
90 | feature_flags: Arc::new(feature_flags), | ||
91 | debug_data: Default::default(), | ||
92 | }; | ||
93 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | ||
94 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); | ||
95 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); | ||
96 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | ||
97 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | ||
98 | db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | ||
99 | db.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); | ||
100 | db | ||
101 | } | ||
102 | } | ||
103 | |||
104 | impl salsa::ParallelDatabase for RootDatabase { | ||
105 | fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { | ||
106 | salsa::Snapshot::new(RootDatabase { | ||
107 | runtime: self.runtime.snapshot(self), | ||
108 | last_gc: self.last_gc, | ||
109 | last_gc_check: self.last_gc_check, | ||
110 | feature_flags: Arc::clone(&self.feature_flags), | ||
111 | debug_data: Arc::clone(&self.debug_data), | ||
112 | }) | ||
113 | } | ||
114 | } | ||
115 | |||
116 | #[salsa::query_group(LineIndexDatabaseStorage)] | ||
117 | pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { | ||
118 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; | ||
119 | } | ||
120 | |||
121 | fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | ||
122 | let text = db.file_text(file_id); | ||
123 | Arc::new(LineIndex::new(&*text)) | ||
124 | } | ||
125 | |||
126 | #[derive(Debug, Default, Clone)] | ||
127 | pub(crate) struct DebugData { | ||
128 | pub(crate) root_paths: FxHashMap<SourceRootId, String>, | ||
129 | pub(crate) crate_names: FxHashMap<CrateId, String>, | ||
130 | } | ||
131 | |||
132 | impl DebugData { | ||
133 | pub(crate) fn merge(&mut self, other: DebugData) { | ||
134 | self.root_paths.extend(other.root_paths.into_iter()); | ||
135 | self.crate_names.extend(other.crate_names.into_iter()); | ||
136 | } | ||
137 | } | ||