From abf2179c0b606730acadc61451739baecfa33a5d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 14 Oct 2019 16:20:55 +0300 Subject: Prepare SourceDatabase API for lazy file loading --- crates/ra_hir/src/mock.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/mock.rs') diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 827424983..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}; use parking_lot::Mutex; use ra_cfg::CfgOptions; use ra_db::{ - salsa, CrateGraph, CrateId, Edition, FileId, FilePosition, SourceDatabase, SourceRoot, - SourceRootId, + salsa, CrateGraph, CrateId, Edition, FileId, FileLoader, FileLoaderDelegate, FilePosition, + SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId, }; -use relative_path::RelativePathBuf; +use relative_path::{RelativePath, RelativePathBuf}; use rustc_hash::FxHashMap; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; @@ -17,6 +17,7 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink}; pub const WORKSPACE: SourceRootId = SourceRootId(0); #[salsa::database( + ra_db::SourceDatabaseExtStorage, ra_db::SourceDatabaseStorage, db::InternDatabaseStorage, db::AstDatabaseStorage, @@ -34,6 +35,22 @@ pub struct MockDatabase { impl panic::RefUnwindSafe for MockDatabase {} +impl FileLoader for MockDatabase { + fn file_text(&self, file_id: FileId) -> Arc { + FileLoaderDelegate(self).file_text(file_id) + } + fn resolve_relative_path( + &self, + anchor: FileId, + relative_path: &RelativePath, + ) -> Option { + FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) + } + fn relevant_crates(&self, file_id: FileId) -> Arc> { + FileLoaderDelegate(self).relevant_crates(file_id) + } +} + impl HirDebugHelper for MockDatabase { fn crate_name(&self, krate: CrateId) -> Option { self.crate_names.get(&krate).cloned() -- cgit v1.2.3