mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
6e24321e45
They allow to represent paths like `#[path = "C:\path.rs"] mod foo;` in a lossless cross-platform & network-transparent way.
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
//! Database used for testing `hir_expand`.
|
|
|
|
use std::{
|
|
fmt, panic,
|
|
sync::{Arc, Mutex},
|
|
};
|
|
|
|
use base_db::{salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate};
|
|
use rustc_hash::FxHashSet;
|
|
|
|
#[salsa::database(
|
|
base_db::SourceDatabaseExtStorage,
|
|
base_db::SourceDatabaseStorage,
|
|
crate::db::AstDatabaseStorage
|
|
)]
|
|
#[derive(Default)]
|
|
pub(crate) struct TestDB {
|
|
storage: salsa::Storage<TestDB>,
|
|
events: Mutex<Option<Vec<salsa::Event>>>,
|
|
}
|
|
|
|
impl fmt::Debug for TestDB {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.debug_struct("TestDB").finish()
|
|
}
|
|
}
|
|
|
|
impl salsa::Database for TestDB {
|
|
fn salsa_event(&self, event: salsa::Event) {
|
|
let mut events = self.events.lock().unwrap();
|
|
if let Some(events) = &mut *events {
|
|
events.push(event);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl panic::RefUnwindSafe for TestDB {}
|
|
|
|
impl FileLoader for TestDB {
|
|
fn file_text(&self, file_id: FileId) -> Arc<String> {
|
|
FileLoaderDelegate(self).file_text(file_id)
|
|
}
|
|
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
|
|
FileLoaderDelegate(self).resolve_path(path)
|
|
}
|
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
|
}
|
|
}
|