diff options
author | Florian Diebold <[email protected]> | 2019-12-30 13:25:19 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-01-11 22:33:04 +0000 |
commit | 22b412f1a9d245cc3d3774dab9408e3a39a52025 (patch) | |
tree | 9651434730d78f05ecceb541f5eb28e99543a084 /crates/ra_hir_def/src/test_db.rs | |
parent | 877fda04c5a37241b09f155847d7e27b20875b63 (diff) |
find_path WIP
Diffstat (limited to 'crates/ra_hir_def/src/test_db.rs')
-rw-r--r-- | crates/ra_hir_def/src/test_db.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs index 54e3a84bd..a403f183f 100644 --- a/crates/ra_hir_def/src/test_db.rs +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -6,6 +6,7 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath}; | 8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath}; |
9 | use crate::db::DefDatabase; | ||
9 | 10 | ||
10 | #[salsa::database( | 11 | #[salsa::database( |
11 | ra_db::SourceDatabaseExtStorage, | 12 | ra_db::SourceDatabaseExtStorage, |
@@ -54,6 +55,18 @@ impl FileLoader for TestDB { | |||
54 | } | 55 | } |
55 | 56 | ||
56 | impl TestDB { | 57 | impl TestDB { |
58 | pub fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { | ||
59 | for &krate in self.relevant_crates(file_id).iter() { | ||
60 | let crate_def_map = self.crate_def_map(krate); | ||
61 | for (local_id, data) in crate_def_map.modules.iter() { | ||
62 | if data.origin.file_id() == Some(file_id) { | ||
63 | return crate::ModuleId { krate, local_id }; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | panic!("Can't find module for file") | ||
68 | } | ||
69 | |||
57 | pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> { | 70 | pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> { |
58 | *self.events.lock().unwrap() = Some(Vec::new()); | 71 | *self.events.lock().unwrap() = Some(Vec::new()); |
59 | f(); | 72 | f(); |