aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-05 14:07:30 +0100
committerAleksey Kladov <[email protected]>2020-06-05 14:07:30 +0100
commitbba374bab2ee53643a899e7ea459b4ab27663bd0 (patch)
tree77610cd5b460dba0c350a5a9504b813bb3e8be98 /crates/ra_db
parente63c00f100e960f7b72997026b4b2cd3cd29774b (diff)
More direct signature for resolve_path
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/lib.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 07e1b8aba..2e63cb46e 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -89,7 +89,7 @@ pub const DEFAULT_LRU_CAP: usize = 128;
89pub trait FileLoader { 89pub trait FileLoader {
90 /// Text of the file. 90 /// Text of the file.
91 fn file_text(&self, file_id: FileId) -> Arc<String>; 91 fn file_text(&self, file_id: FileId) -> Arc<String>;
92 fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId>; 92 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
93 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>; 93 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>;
94 94
95 fn resolve_extern_path( 95 fn resolve_extern_path(
@@ -154,16 +154,21 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
154 fn file_text(&self, file_id: FileId) -> Arc<String> { 154 fn file_text(&self, file_id: FileId) -> Arc<String> {
155 SourceDatabaseExt::file_text(self.0, file_id) 155 SourceDatabaseExt::file_text(self.0, file_id)
156 } 156 }
157 fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId> { 157 /// Note that we intentionally accept a `&str` and not a `&Path` here. This
158 let path = { 158 /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such,
159 let mut path = self.0.file_relative_path(anchor); 159 /// so the input is guaranteed to be utf-8 string. We might introduce
160 assert!(path.pop()); 160 /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we
161 path.push(relative_path); 161 /// get by with a `&str` for the time being.
162 path.normalize() 162 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
163 let rel_path = {
164 let mut rel_path = self.0.file_relative_path(anchor);
165 assert!(rel_path.pop());
166 rel_path.push(path);
167 rel_path.normalize()
163 }; 168 };
164 let source_root = self.0.file_source_root(anchor); 169 let source_root = self.0.file_source_root(anchor);
165 let source_root = self.0.source_root(source_root); 170 let source_root = self.0.source_root(source_root);
166 source_root.file_by_relative_path(&path) 171 source_root.file_by_relative_path(&rel_path)
167 } 172 }
168 173
169 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { 174 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {