diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir_def/src/test_db.rs | 40 |
3 files changed, 53 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 42e080a72..02bd808fc 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -15,6 +15,9 @@ pub mod builtin_type; | |||
15 | pub mod adt; | 15 | pub mod adt; |
16 | pub mod diagnostics; | 16 | pub mod diagnostics; |
17 | 17 | ||
18 | #[cfg(test)] | ||
19 | mod test_db; | ||
20 | |||
18 | // FIXME: this should be private | 21 | // FIXME: this should be private |
19 | pub mod nameres; | 22 | pub mod nameres; |
20 | 23 | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 8a96d3d31..0bc36910c 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -739,17 +739,18 @@ fn is_macro_rules(path: &Path) -> bool { | |||
739 | path.as_ident() == Some(&name::MACRO_RULES) | 739 | path.as_ident() == Some(&name::MACRO_RULES) |
740 | } | 740 | } |
741 | 741 | ||
742 | #[cfg(never)] | 742 | #[cfg(test)] |
743 | mod tests { | 743 | mod tests { |
744 | use ra_db::SourceDatabase; | ||
745 | |||
746 | use super::*; | ||
747 | use crate::{db::DefDatabase, mock::MockDatabase, Crate}; | ||
748 | use ra_arena::Arena; | 744 | use ra_arena::Arena; |
745 | use ra_db::{fixture::WithFixture, SourceDatabase}; | ||
749 | use rustc_hash::FxHashSet; | 746 | use rustc_hash::FxHashSet; |
750 | 747 | ||
748 | use crate::{db::DefDatabase2, test_db::TestDB}; | ||
749 | |||
750 | use super::*; | ||
751 | |||
751 | fn do_collect_defs( | 752 | fn do_collect_defs( |
752 | db: &impl DefDatabase, | 753 | db: &impl DefDatabase2, |
753 | def_map: CrateDefMap, | 754 | def_map: CrateDefMap, |
754 | monitor: MacroStackMonitor, | 755 | monitor: MacroStackMonitor, |
755 | ) -> CrateDefMap { | 756 | ) -> CrateDefMap { |
@@ -768,12 +769,11 @@ mod tests { | |||
768 | } | 769 | } |
769 | 770 | ||
770 | fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { | 771 | fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { |
771 | let (db, _source_root, _) = MockDatabase::with_single_file(&code); | 772 | let (db, _file_id) = TestDB::with_single_file(&code); |
772 | let crate_id = db.crate_graph().iter().next().unwrap(); | 773 | let krate = db.crate_graph().iter().next().unwrap(); |
773 | let krate = Crate { crate_id }; | ||
774 | 774 | ||
775 | let def_map = { | 775 | let def_map = { |
776 | let edition = krate.edition(&db); | 776 | let edition = db.crate_graph().edition(krate); |
777 | let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default(); | 777 | let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default(); |
778 | let root = modules.alloc(ModuleData::default()); | 778 | let root = modules.alloc(ModuleData::default()); |
779 | CrateDefMap { | 779 | CrateDefMap { |
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs new file mode 100644 index 000000000..67714c68e --- /dev/null +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -0,0 +1,40 @@ | |||
1 | use std::{panic, sync::Arc}; | ||
2 | |||
3 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; | ||
4 | use relative_path::RelativePath; | ||
5 | |||
6 | #[salsa::database( | ||
7 | ra_db::SourceDatabaseExtStorage, | ||
8 | ra_db::SourceDatabaseStorage, | ||
9 | hir_expand::db::AstDatabaseStorage, | ||
10 | crate::db::InternDatabaseStorage, | ||
11 | crate::db::DefDatabase2Storage | ||
12 | )] | ||
13 | #[derive(Debug, Default)] | ||
14 | pub struct TestDB { | ||
15 | runtime: salsa::Runtime<TestDB>, | ||
16 | } | ||
17 | |||
18 | impl salsa::Database for TestDB { | ||
19 | fn salsa_runtime(&self) -> &salsa::Runtime<Self> { | ||
20 | &self.runtime | ||
21 | } | ||
22 | } | ||
23 | |||
24 | impl panic::RefUnwindSafe for TestDB {} | ||
25 | |||
26 | impl FileLoader for TestDB { | ||
27 | fn file_text(&self, file_id: FileId) -> Arc<String> { | ||
28 | FileLoaderDelegate(self).file_text(file_id) | ||
29 | } | ||
30 | fn resolve_relative_path( | ||
31 | &self, | ||
32 | anchor: FileId, | ||
33 | relative_path: &RelativePath, | ||
34 | ) -> Option<FileId> { | ||
35 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
36 | } | ||
37 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | ||
38 | FileLoaderDelegate(self).relevant_crates(file_id) | ||
39 | } | ||
40 | } | ||