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