aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/doc_tests.rs3
-rw-r--r--crates/ra_assists/src/lib.rs8
-rw-r--r--crates/ra_assists/src/test_db.rs43
3 files changed, 50 insertions, 4 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs
index 2500a5ab7..a8f8446cb 100644
--- a/crates/ra_assists/src/doc_tests.rs
+++ b/crates/ra_assists/src/doc_tests.rs
@@ -5,10 +5,11 @@
5 5
6mod generated; 6mod generated;
7 7
8use hir::mock::TestDB;
9use ra_db::{fixture::WithFixture, FileRange}; 8use ra_db::{fixture::WithFixture, FileRange};
10use test_utils::{assert_eq_text, extract_range_or_offset}; 9use test_utils::{assert_eq_text, extract_range_or_offset};
11 10
11use crate::test_db::TestDB;
12
12fn check(assist_id: &str, before: &str, after: &str) { 13fn check(assist_id: &str, before: &str, after: &str) {
13 let (selection, before) = extract_range_or_offset(before); 14 let (selection, before) = extract_range_or_offset(before);
14 let (db, file_id) = TestDB::with_single_file(&before); 15 let (db, file_id) = TestDB::with_single_file(&before);
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 85fb72395..39c1c283f 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -9,6 +9,8 @@ mod assist_ctx;
9mod marks; 9mod marks;
10#[cfg(test)] 10#[cfg(test)]
11mod doc_tests; 11mod doc_tests;
12#[cfg(test)]
13mod test_db;
12 14
13use hir::db::HirDatabase; 15use hir::db::HirDatabase;
14use ra_db::FileRange; 16use ra_db::FileRange;
@@ -146,12 +148,11 @@ mod assists {
146 148
147#[cfg(test)] 149#[cfg(test)]
148mod helpers { 150mod helpers {
149 use hir::mock::TestDB;
150 use ra_db::{fixture::WithFixture, FileRange}; 151 use ra_db::{fixture::WithFixture, FileRange};
151 use ra_syntax::TextRange; 152 use ra_syntax::TextRange;
152 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; 153 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
153 154
154 use crate::{Assist, AssistCtx}; 155 use crate::{test_db::TestDB, Assist, AssistCtx};
155 156
156 pub(crate) fn check_assist( 157 pub(crate) fn check_assist(
157 assist: fn(AssistCtx<TestDB>) -> Option<Assist>, 158 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
@@ -268,11 +269,12 @@ mod helpers {
268 269
269#[cfg(test)] 270#[cfg(test)]
270mod tests { 271mod tests {
271 use hir::mock::TestDB;
272 use ra_db::{fixture::WithFixture, FileRange}; 272 use ra_db::{fixture::WithFixture, FileRange};
273 use ra_syntax::TextRange; 273 use ra_syntax::TextRange;
274 use test_utils::{extract_offset, extract_range}; 274 use test_utils::{extract_offset, extract_range};
275 275
276 use crate::test_db::TestDB;
277
276 #[test] 278 #[test]
277 fn assist_order_field_struct() { 279 fn assist_order_field_struct() {
278 let before = "struct Foo { <|>bar: u32 }"; 280 let before = "struct Foo { <|>bar: u32 }";
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs
new file mode 100644
index 000000000..7b196561a
--- /dev/null
+++ b/crates/ra_assists/src/test_db.rs
@@ -0,0 +1,43 @@
1use std::sync::Arc;
2
3use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath};
4
5#[salsa::database(
6 ra_db::SourceDatabaseExtStorage,
7 ra_db::SourceDatabaseStorage,
8 hir::db::InternDatabaseStorage,
9 hir::db::AstDatabaseStorage,
10 hir::db::DefDatabaseStorage,
11 hir::db::DefDatabase2Storage,
12 hir::db::HirDatabaseStorage
13)]
14#[derive(Debug, Default)]
15pub struct TestDB {
16 runtime: salsa::Runtime<TestDB>,
17}
18
19impl salsa::Database for TestDB {
20 fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
21 &self.runtime
22 }
23}
24
25impl std::panic::RefUnwindSafe for TestDB {}
26
27impl FileLoader for TestDB {
28 fn file_text(&self, file_id: FileId) -> Arc<String> {
29 FileLoaderDelegate(self).file_text(file_id)
30 }
31 fn resolve_relative_path(
32 &self,
33 anchor: FileId,
34 relative_path: &RelativePath,
35 ) -> Option<FileId> {
36 FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
37 }
38 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
39 FileLoaderDelegate(self).relevant_crates(file_id)
40 }
41}
42
43impl hir::debug::HirDebugHelper for TestDB {}