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-05 14:15:31 +0100
committerGitHub <[email protected]>2020-06-05 14:15:31 +0100
commitd06df2c3e7e2b6eacda29cb1c715f1a1f2ada032 (patch)
treea1a1439aa2cd1b4cba3c559f41bfbde24a08aa36 /crates/ra_db/src/lib.rs
parentf98d057218ca30d052da2a119fa0b3108ba3a091 (diff)
parentcb9d9040f7e5cb5971deabe3b66045010576a689 (diff)
Merge #4756
4756: Cleanup resolution of file paths r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src/lib.rs')
-rw-r--r--crates/ra_db/src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index fd4280de2..2e63cb46e 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -89,8 +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_relative_path(&self, anchor: FileId, relative_path: &RelativePath) 92 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
93 -> Option<FileId>;
94 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>; 93 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>;
95 94
96 fn resolve_extern_path( 95 fn resolve_extern_path(
@@ -155,20 +154,21 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
155 fn file_text(&self, file_id: FileId) -> Arc<String> { 154 fn file_text(&self, file_id: FileId) -> Arc<String> {
156 SourceDatabaseExt::file_text(self.0, file_id) 155 SourceDatabaseExt::file_text(self.0, file_id)
157 } 156 }
158 fn resolve_relative_path( 157 /// Note that we intentionally accept a `&str` and not a `&Path` here. This
159 &self, 158 /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such,
160 anchor: FileId, 159 /// so the input is guaranteed to be utf-8 string. We might introduce
161 relative_path: &RelativePath, 160 /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we
162 ) -> Option<FileId> { 161 /// get by with a `&str` for the time being.
163 let path = { 162 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
164 let mut path = self.0.file_relative_path(anchor); 163 let rel_path = {
165 assert!(path.pop()); 164 let mut rel_path = self.0.file_relative_path(anchor);
166 path.push(relative_path); 165 assert!(rel_path.pop());
167 path.normalize() 166 rel_path.push(path);
167 rel_path.normalize()
168 }; 168 };
169 let source_root = self.0.file_source_root(anchor); 169 let source_root = self.0.file_source_root(anchor);
170 let source_root = self.0.source_root(source_root); 170 let source_root = self.0.source_root(source_root);
171 source_root.file_by_relative_path(&path) 171 source_root.file_by_relative_path(&rel_path)
172 } 172 }
173 173
174 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { 174 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {