aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/db.rs')
-rw-r--r--crates/ra_ide_api/src/db.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index ea0714add..9146b647a 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -4,8 +4,10 @@ use std::sync::Arc;
4 4
5use ra_db::{ 5use ra_db::{
6 salsa::{self, Database, Durability}, 6 salsa::{self, Database, Durability},
7 Canceled, CheckCanceled, CrateId, FileId, SourceDatabase, SourceRootId, 7 Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase,
8 SourceDatabaseExt, SourceRootId,
8}; 9};
10use relative_path::RelativePath;
9use rustc_hash::FxHashMap; 11use rustc_hash::FxHashMap;
10 12
11use crate::{ 13use crate::{
@@ -15,6 +17,7 @@ use crate::{
15 17
16#[salsa::database( 18#[salsa::database(
17 ra_db::SourceDatabaseStorage, 19 ra_db::SourceDatabaseStorage,
20 ra_db::SourceDatabaseExtStorage,
18 LineIndexDatabaseStorage, 21 LineIndexDatabaseStorage,
19 symbol_index::SymbolsDatabaseStorage, 22 symbol_index::SymbolsDatabaseStorage,
20 hir::db::InternDatabaseStorage, 23 hir::db::InternDatabaseStorage,
@@ -31,6 +34,22 @@ pub(crate) struct RootDatabase {
31 pub(crate) last_gc_check: crate::wasm_shims::Instant, 34 pub(crate) last_gc_check: crate::wasm_shims::Instant,
32} 35}
33 36
37impl FileLoader for RootDatabase {
38 fn file_text(&self, file_id: FileId) -> Arc<String> {
39 FileLoaderDelegate(self).file_text(file_id)
40 }
41 fn resolve_relative_path(
42 &self,
43 anchor: FileId,
44 relative_path: &RelativePath,
45 ) -> Option<FileId> {
46 FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
47 }
48 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
49 FileLoaderDelegate(self).relevant_crates(file_id)
50 }
51}
52
34impl hir::debug::HirDebugHelper for RootDatabase { 53impl hir::debug::HirDebugHelper for RootDatabase {
35 fn crate_name(&self, krate: CrateId) -> Option<String> { 54 fn crate_name(&self, krate: CrateId) -> Option<String> {
36 self.debug_data.crate_names.get(&krate).cloned() 55 self.debug_data.crate_names.get(&krate).cloned()
@@ -39,7 +58,7 @@ impl hir::debug::HirDebugHelper for RootDatabase {
39 let source_root_id = self.file_source_root(file_id); 58 let source_root_id = self.file_source_root(file_id);
40 let source_root_path = self.debug_data.root_paths.get(&source_root_id)?; 59 let source_root_path = self.debug_data.root_paths.get(&source_root_id)?;
41 let file_path = self.file_relative_path(file_id); 60 let file_path = self.file_relative_path(file_id);
42 Some(format!("{}/{}", source_root_path, file_path.display())) 61 Some(format!("{}/{}", source_root_path, file_path))
43 } 62 }
44} 63}
45 64
@@ -104,7 +123,7 @@ pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
104 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; 123 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
105} 124}
106 125
107fn line_index(db: &impl ra_db::SourceDatabase, file_id: FileId) -> Arc<LineIndex> { 126fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
108 let text = db.file_text(file_id); 127 let text = db.file_text(file_id);
109 Arc::new(LineIndex::new(&*text)) 128 Arc::new(LineIndex::new(&*text))
110} 129}