From bba374bab2ee53643a899e7ea459b4ab27663bd0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 5 Jun 2020 15:07:30 +0200 Subject: More direct signature for resolve_path --- crates/ra_db/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'crates/ra_db') 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; pub trait FileLoader { /// Text of the file. fn file_text(&self, file_id: FileId) -> Arc; - fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option; + fn resolve_path(&self, anchor: FileId, path: &str) -> Option; fn relevant_crates(&self, file_id: FileId) -> Arc>; fn resolve_extern_path( @@ -154,16 +154,21 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { fn file_text(&self, file_id: FileId) -> Arc { SourceDatabaseExt::file_text(self.0, file_id) } - fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option { - let path = { - let mut path = self.0.file_relative_path(anchor); - assert!(path.pop()); - path.push(relative_path); - path.normalize() + /// Note that we intentionally accept a `&str` and not a `&Path` here. This + /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such, + /// so the input is guaranteed to be utf-8 string. We might introduce + /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we + /// get by with a `&str` for the time being. + fn resolve_path(&self, anchor: FileId, path: &str) -> Option { + let rel_path = { + let mut rel_path = self.0.file_relative_path(anchor); + assert!(rel_path.pop()); + rel_path.push(path); + rel_path.normalize() }; let source_root = self.0.file_source_root(anchor); let source_root = self.0.source_root(source_root); - source_root.file_by_relative_path(&path) + source_root.file_by_relative_path(&rel_path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { -- cgit v1.2.3