aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/mock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r--crates/ra_hir/src/mock.rs27
1 files changed, 8 insertions, 19 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 6e6f2f04b..4145c8048 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -2,13 +2,13 @@ use std::{sync::Arc, panic};
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use ra_db::{ 4use ra_db::{
5 LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, 5 BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId,
6 salsa::{self, Database}, 6 salsa::{self, Database},
7}; 7};
8use relative_path::RelativePathBuf; 8use relative_path::RelativePathBuf;
9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
10 10
11use crate::{db, DefId, DefLoc, MacroCallId, MacroCallLoc}; 11use crate::{db, HirInterner};
12 12
13pub const WORKSPACE: SourceRootId = SourceRootId(0); 13pub const WORKSPACE: SourceRootId = SourceRootId(0);
14 14
@@ -16,7 +16,7 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
16pub(crate) struct MockDatabase { 16pub(crate) struct MockDatabase {
17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
18 runtime: salsa::Runtime<MockDatabase>, 18 runtime: salsa::Runtime<MockDatabase>,
19 id_maps: Arc<IdMaps>, 19 interner: Arc<HirInterner>,
20 file_counter: u32, 20 file_counter: u32,
21} 21}
22 22
@@ -123,12 +123,6 @@ impl MockDatabase {
123 } 123 }
124} 124}
125 125
126#[derive(Debug, Default)]
127struct IdMaps {
128 defs: LocationIntener<DefLoc, DefId>,
129 macros: LocationIntener<MacroCallLoc, MacroCallId>,
130}
131
132impl salsa::Database for MockDatabase { 126impl salsa::Database for MockDatabase {
133 fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> { 127 fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> {
134 &self.runtime 128 &self.runtime
@@ -147,7 +141,7 @@ impl Default for MockDatabase {
147 let mut db = MockDatabase { 141 let mut db = MockDatabase {
148 events: Default::default(), 142 events: Default::default(),
149 runtime: salsa::Runtime::default(), 143 runtime: salsa::Runtime::default(),
150 id_maps: Default::default(), 144 interner: Default::default(),
151 file_counter: 0, 145 file_counter: 0,
152 }; 146 };
153 db.query_mut(ra_db::CrateGraphQuery) 147 db.query_mut(ra_db::CrateGraphQuery)
@@ -165,7 +159,7 @@ impl salsa::ParallelDatabase for MockDatabase {
165 salsa::Snapshot::new(MockDatabase { 159 salsa::Snapshot::new(MockDatabase {
166 events: Default::default(), 160 events: Default::default(),
167 runtime: self.runtime.snapshot(self), 161 runtime: self.runtime.snapshot(self),
168 id_maps: self.id_maps.clone(), 162 interner: Arc::clone(&self.interner),
169 file_counter: self.file_counter, 163 file_counter: self.file_counter,
170 }) 164 })
171 } 165 }
@@ -173,14 +167,9 @@ impl salsa::ParallelDatabase for MockDatabase {
173 167
174impl BaseDatabase for MockDatabase {} 168impl BaseDatabase for MockDatabase {}
175 169
176impl AsRef<LocationIntener<DefLoc, DefId>> for MockDatabase { 170impl AsRef<HirInterner> for MockDatabase {
177 fn as_ref(&self) -> &LocationIntener<DefLoc, DefId> { 171 fn as_ref(&self) -> &HirInterner {
178 &self.id_maps.defs 172 &self.interner
179 }
180}
181impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>> for MockDatabase {
182 fn as_ref(&self) -> &LocationIntener<MacroCallLoc, MacroCallId> {
183 &self.id_maps.macros
184 } 173 }
185} 174}
186 175