diff options
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r-- | crates/ra_hir/src/mock.rs | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index f750986b8..0b278deb3 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -5,10 +5,10 @@ use std::{panic, sync::Arc}; | |||
5 | use parking_lot::Mutex; | 5 | use parking_lot::Mutex; |
6 | use ra_cfg::CfgOptions; | 6 | use ra_cfg::CfgOptions; |
7 | use ra_db::{ | 7 | use ra_db::{ |
8 | salsa, CrateGraph, CrateId, Edition, FileId, FilePosition, SourceDatabase, SourceRoot, | 8 | salsa, CrateGraph, CrateId, Edition, FileId, FileLoader, FileLoaderDelegate, FilePosition, |
9 | SourceRootId, | 9 | SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId, |
10 | }; | 10 | }; |
11 | use relative_path::RelativePathBuf; | 11 | use relative_path::{RelativePath, RelativePathBuf}; |
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
13 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; | 13 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; |
14 | 14 | ||
@@ -17,6 +17,7 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink}; | |||
17 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 17 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
18 | 18 | ||
19 | #[salsa::database( | 19 | #[salsa::database( |
20 | ra_db::SourceDatabaseExtStorage, | ||
20 | ra_db::SourceDatabaseStorage, | 21 | ra_db::SourceDatabaseStorage, |
21 | db::InternDatabaseStorage, | 22 | db::InternDatabaseStorage, |
22 | db::AstDatabaseStorage, | 23 | db::AstDatabaseStorage, |
@@ -34,6 +35,22 @@ pub struct MockDatabase { | |||
34 | 35 | ||
35 | impl panic::RefUnwindSafe for MockDatabase {} | 36 | impl panic::RefUnwindSafe for MockDatabase {} |
36 | 37 | ||
38 | impl FileLoader for MockDatabase { | ||
39 | fn file_text(&self, file_id: FileId) -> Arc<String> { | ||
40 | FileLoaderDelegate(self).file_text(file_id) | ||
41 | } | ||
42 | fn resolve_relative_path( | ||
43 | &self, | ||
44 | anchor: FileId, | ||
45 | relative_path: &RelativePath, | ||
46 | ) -> Option<FileId> { | ||
47 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
48 | } | ||
49 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | ||
50 | FileLoaderDelegate(self).relevant_crates(file_id) | ||
51 | } | ||
52 | } | ||
53 | |||
37 | impl HirDebugHelper for MockDatabase { | 54 | impl HirDebugHelper for MockDatabase { |
38 | fn crate_name(&self, krate: CrateId) -> Option<String> { | 55 | fn crate_name(&self, krate: CrateId) -> Option<String> { |
39 | self.crate_names.get(&krate).cloned() | 56 | self.crate_names.get(&krate).cloned() |
@@ -278,7 +295,10 @@ macro_rules! crate_graph { | |||
278 | $crate_path:literal, | 295 | $crate_path:literal, |
279 | $($edition:literal,)? | 296 | $($edition:literal,)? |
280 | [$($dep:literal),*] | 297 | [$($dep:literal),*] |
281 | $(,$cfg:expr)? | 298 | $(, cfg = { |
299 | $($key:literal $(= $value:literal)?),* | ||
300 | $(,)? | ||
301 | })? | ||
282 | ), | 302 | ), |
283 | )*) => {{ | 303 | )*) => {{ |
284 | let mut res = $crate::mock::CrateGraphFixture::default(); | 304 | let mut res = $crate::mock::CrateGraphFixture::default(); |
@@ -286,7 +306,19 @@ macro_rules! crate_graph { | |||
286 | #[allow(unused_mut, unused_assignments)] | 306 | #[allow(unused_mut, unused_assignments)] |
287 | let mut edition = ra_db::Edition::Edition2018; | 307 | let mut edition = ra_db::Edition::Edition2018; |
288 | $(edition = ra_db::Edition::from_string($edition);)? | 308 | $(edition = ra_db::Edition::from_string($edition);)? |
289 | let cfg_options = { ::ra_cfg::CfgOptions::default() $(; $cfg)? }; | 309 | let cfg_options = { |
310 | #[allow(unused_mut)] | ||
311 | let mut cfg = ::ra_cfg::CfgOptions::default(); | ||
312 | $( | ||
313 | $( | ||
314 | if 0 == 0 $(+ { drop($value); 1})? { | ||
315 | cfg.insert_atom($key.into()); | ||
316 | } | ||
317 | $(cfg.insert_key_value($key.into(), $value.into());)? | ||
318 | )* | ||
319 | )? | ||
320 | cfg | ||
321 | }; | ||
290 | res.0.push(( | 322 | res.0.push(( |
291 | $crate_name.to_string(), | 323 | $crate_name.to_string(), |
292 | ($crate_path.to_string(), edition, cfg_options, vec![$($dep.to_string()),*]) | 324 | ($crate_path.to_string(), edition, cfg_options, vec![$($dep.to_string()),*]) |