aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-23 16:53:56 +0100
committerGitHub <[email protected]>2020-06-23 16:53:56 +0100
commit0c12c4f9609ee72487af9b55a558b01af73ffe3e (patch)
tree29be52a980b4cae72f46a48c48135a15e31641e0 /crates/ra_db/src/lib.rs
parent7aa66371ee3e8b31217513204c8b4f683584419d (diff)
parentdad1333b48c38bc7a5628fc0ff5304d003776a85 (diff)
Merge #4976
4976: New VFS r=matklad a=matklad Still a draft, but mostly working already. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src/lib.rs')
-rw-r--r--crates/ra_db/src/lib.rs28
1 files changed, 6 insertions, 22 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 80ddb6058..875290259 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -12,12 +12,13 @@ use rustc_hash::FxHashSet;
12pub use crate::{ 12pub use crate::{
13 cancellation::Canceled, 13 cancellation::Canceled,
14 input::{ 14 input::{
15 CrateData, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ExternSource, 15 CrateData, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, FileId, ProcMacroId,
16 ExternSourceId, FileId, ProcMacroId, SourceRoot, SourceRootId, 16 SourceRoot, SourceRootId,
17 }, 17 },
18}; 18};
19pub use relative_path::{RelativePath, RelativePathBuf}; 19pub use relative_path::{RelativePath, RelativePathBuf};
20pub use salsa; 20pub use salsa;
21pub use vfs::{file_set::FileSet, AbsPathBuf, VfsPath};
21 22
22#[macro_export] 23#[macro_export]
23macro_rules! impl_intern_key { 24macro_rules! impl_intern_key {
@@ -125,8 +126,6 @@ pub trait SourceDatabaseExt: SourceDatabase {
125 #[salsa::input] 126 #[salsa::input]
126 fn file_text(&self, file_id: FileId) -> Arc<String>; 127 fn file_text(&self, file_id: FileId) -> Arc<String>;
127 /// Path to a file, relative to the root of its source root. 128 /// Path to a file, relative to the root of its source root.
128 #[salsa::input]
129 fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
130 /// Source root of the file. 129 /// Source root of the file.
131 #[salsa::input] 130 #[salsa::input]
132 fn file_source_root(&self, file_id: FileId) -> SourceRootId; 131 fn file_source_root(&self, file_id: FileId) -> SourceRootId;
@@ -161,24 +160,9 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
161 } 160 }
162 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 161 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
163 // FIXME: this *somehow* should be platform agnostic... 162 // FIXME: this *somehow* should be platform agnostic...
164 if std::path::Path::new(path).is_absolute() { 163 let source_root = self.0.file_source_root(anchor);
165 let krate = *self.relevant_crates(anchor).iter().next()?; 164 let source_root = self.0.source_root(source_root);
166 let (extern_source_id, relative_file) = 165 source_root.file_set.resolve_path(anchor, path)
167 self.0.crate_graph()[krate].extern_source.extern_path(path.as_ref())?;
168
169 let source_root = self.0.source_root(SourceRootId(extern_source_id.0));
170 source_root.file_by_relative_path(&relative_file)
171 } else {
172 let rel_path = {
173 let mut rel_path = self.0.file_relative_path(anchor);
174 assert!(rel_path.pop());
175 rel_path.push(path);
176 rel_path.normalize()
177 };
178 let source_root = self.0.file_source_root(anchor);
179 let source_root = self.0.source_root(source_root);
180 source_root.file_by_relative_path(&rel_path)
181 }
182 } 166 }
183 167
184 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 168 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {