diff options
author | Aleksey Kladov <[email protected]> | 2020-12-09 16:01:15 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-12-09 16:07:05 +0000 |
commit | 6e24321e4579d25686982002ed18f321db23cb9f (patch) | |
tree | 08f0fd7d99ad22a3d1db782482b66548e99ba8b2 /crates/base_db | |
parent | 5e3891c2559de5a6540d69bc14ded281484479f9 (diff) |
Introduce anchored_path
They allow to represent paths like `#[path = "C:\path.rs"] mod foo;`
in a lossless cross-platform & network-transparent way.
Diffstat (limited to 'crates/base_db')
-rw-r--r-- | crates/base_db/src/lib.rs | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index a2cc1e099..595f28ada 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs | |||
@@ -91,12 +91,7 @@ pub const DEFAULT_LRU_CAP: usize = 128; | |||
91 | pub trait FileLoader { | 91 | pub trait FileLoader { |
92 | /// Text of the file. | 92 | /// Text of the file. |
93 | fn file_text(&self, file_id: FileId) -> Arc<String>; | 93 | fn file_text(&self, file_id: FileId) -> Arc<String>; |
94 | /// Note that we intentionally accept a `&str` and not a `&Path` here. This | 94 | fn resolve_path(&self, path: AnchoredPath) -> Option<FileId>; |
95 | /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such, | ||
96 | /// so the input is guaranteed to be utf-8 string. One might be tempted to | ||
97 | /// introduce some kind of "utf-8 path with / separators", but that's a bad idea. Behold | ||
98 | /// `#[path = "C://no/way"]` | ||
99 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>; | ||
100 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; | 95 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; |
101 | } | 96 | } |
102 | 97 | ||
@@ -155,8 +150,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> { | |||
155 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 150 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
156 | SourceDatabaseExt::file_text(self.0, file_id) | 151 | SourceDatabaseExt::file_text(self.0, file_id) |
157 | } | 152 | } |
158 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { | 153 | fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> { |
159 | let path = AnchoredPath { anchor, path }; | ||
160 | // FIXME: this *somehow* should be platform agnostic... | 154 | // FIXME: this *somehow* should be platform agnostic... |
161 | let source_root = self.0.file_source_root(path.anchor); | 155 | let source_root = self.0.file_source_root(path.anchor); |
162 | let source_root = self.0.source_root(source_root); | 156 | let source_root = self.0.source_root(source_root); |