aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/db.rs')
-rw-r--r--crates/ra_ide_api/src/db.rs36
1 files changed, 8 insertions, 28 deletions
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index a1b666899..ba0eb1cb8 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -1,7 +1,7 @@
1use std::{fmt, sync::Arc}; 1use std::sync::Arc;
2 2
3use ra_db::{ 3use ra_db::{
4 LocationIntener, BaseDatabase, FileId, Canceled, 4 BaseDatabase, FileId, Canceled,
5 salsa::{self, Database}, 5 salsa::{self, Database},
6}; 6};
7 7
@@ -10,21 +10,7 @@ use crate::{symbol_index, LineIndex};
10#[derive(Debug)] 10#[derive(Debug)]
11pub(crate) struct RootDatabase { 11pub(crate) struct RootDatabase {
12 runtime: salsa::Runtime<RootDatabase>, 12 runtime: salsa::Runtime<RootDatabase>,
13 id_maps: Arc<IdMaps>, 13 interner: Arc<hir::HirInterner>,
14}
15
16#[derive(Default)]
17struct IdMaps {
18 defs: LocationIntener<hir::DefLoc, hir::DefId>,
19 macros: LocationIntener<hir::MacroCallLoc, hir::MacroCallId>,
20}
21
22impl fmt::Debug for IdMaps {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 f.debug_struct("IdMaps")
25 .field("n_defs", &self.defs.len())
26 .finish()
27 }
28} 14}
29 15
30impl salsa::Database for RootDatabase { 16impl salsa::Database for RootDatabase {
@@ -40,7 +26,7 @@ impl Default for RootDatabase {
40 fn default() -> RootDatabase { 26 fn default() -> RootDatabase {
41 let mut db = RootDatabase { 27 let mut db = RootDatabase {
42 runtime: salsa::Runtime::default(), 28 runtime: salsa::Runtime::default(),
43 id_maps: Default::default(), 29 interner: Default::default(),
44 }; 30 };
45 db.query_mut(ra_db::CrateGraphQuery) 31 db.query_mut(ra_db::CrateGraphQuery)
46 .set((), Default::default()); 32 .set((), Default::default());
@@ -56,22 +42,16 @@ impl salsa::ParallelDatabase for RootDatabase {
56 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { 42 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
57 salsa::Snapshot::new(RootDatabase { 43 salsa::Snapshot::new(RootDatabase {
58 runtime: self.runtime.snapshot(self), 44 runtime: self.runtime.snapshot(self),
59 id_maps: self.id_maps.clone(), 45 interner: Arc::clone(&self.interner),
60 }) 46 })
61 } 47 }
62} 48}
63 49
64impl BaseDatabase for RootDatabase {} 50impl BaseDatabase for RootDatabase {}
65 51
66impl AsRef<LocationIntener<hir::DefLoc, hir::DefId>> for RootDatabase { 52impl AsRef<hir::HirInterner> for RootDatabase {
67 fn as_ref(&self) -> &LocationIntener<hir::DefLoc, hir::DefId> { 53 fn as_ref(&self) -> &hir::HirInterner {
68 &self.id_maps.defs 54 &self.interner
69 }
70}
71
72impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabase {
73 fn as_ref(&self) -> &LocationIntener<hir::MacroCallLoc, hir::MacroCallId> {
74 &self.id_maps.macros
75 } 55 }
76} 56}
77 57