diff options
-rw-r--r-- | crates/ra_db/src/lib.rs | 21 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/mod_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/test_db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/test_db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 4 |
7 files changed, 24 insertions, 19 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; | |||
89 | pub trait FileLoader { | 89 | pub 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>> { |
diff --git a/crates/ra_hir_def/src/nameres/mod_resolution.rs b/crates/ra_hir_def/src/nameres/mod_resolution.rs index 7af922c21..cede4a6fc 100644 --- a/crates/ra_hir_def/src/nameres/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/mod_resolution.rs | |||
@@ -61,7 +61,7 @@ impl ModDir { | |||
61 | }; | 61 | }; |
62 | 62 | ||
63 | for candidate in candidate_files.iter() { | 63 | for candidate in candidate_files.iter() { |
64 | if let Some(file_id) = db.resolve_path(file_id, candidate) { | 64 | if let Some(file_id) = db.resolve_path(file_id, candidate.as_str()) { |
65 | let mut root_non_dir_owner = false; | 65 | let mut root_non_dir_owner = false; |
66 | let mut mod_path = RelativePathBuf::new(); | 66 | let mut mod_path = RelativePathBuf::new(); |
67 | if !(candidate.ends_with("mod.rs") || attr_path.is_some()) { | 67 | if !(candidate.ends_with("mod.rs") || attr_path.is_some()) { |
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs index d33b57c93..e7a5182f0 100644 --- a/crates/ra_hir_def/src/test_db.rs +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -58,8 +58,8 @@ impl FileLoader for TestDB { | |||
58 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 58 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
59 | FileLoaderDelegate(self).file_text(file_id) | 59 | FileLoaderDelegate(self).file_text(file_id) |
60 | } | 60 | } |
61 | fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId> { | 61 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
62 | FileLoaderDelegate(self).resolve_path(anchor, relative_path) | 62 | FileLoaderDelegate(self).resolve_path(anchor, path) |
63 | } | 63 | } |
64 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 64 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
65 | FileLoaderDelegate(self).relevant_crates(file_id) | 65 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 4374d9eda..eec5fb8eb 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -8,7 +8,7 @@ use crate::{ | |||
8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; | 8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; |
9 | use either::Either; | 9 | use either::Either; |
10 | use mbe::parse_to_token_tree; | 10 | use mbe::parse_to_token_tree; |
11 | use ra_db::{FileId, RelativePath}; | 11 | use ra_db::FileId; |
12 | use ra_parser::FragmentKind; | 12 | use ra_parser::FragmentKind; |
13 | 13 | ||
14 | macro_rules! register_builtin { | 14 | macro_rules! register_builtin { |
@@ -297,7 +297,7 @@ fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Opti | |||
297 | let call_site = call_id.as_file().original_file(db); | 297 | let call_site = call_id.as_file().original_file(db); |
298 | 298 | ||
299 | // Handle trivial case | 299 | // Handle trivial case |
300 | if let Some(res) = db.resolve_path(call_site, &RelativePath::new(&path)) { | 300 | if let Some(res) = db.resolve_path(call_site, path) { |
301 | // Prevent include itself | 301 | // Prevent include itself |
302 | return if res == call_site { None } else { Some(res) }; | 302 | return if res == call_site { None } else { Some(res) }; |
303 | } | 303 | } |
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs index 60321fa0a..765a2f6d1 100644 --- a/crates/ra_hir_expand/src/test_db.rs +++ b/crates/ra_hir_expand/src/test_db.rs | |||
@@ -41,8 +41,8 @@ impl FileLoader for TestDB { | |||
41 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 41 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
42 | FileLoaderDelegate(self).file_text(file_id) | 42 | FileLoaderDelegate(self).file_text(file_id) |
43 | } | 43 | } |
44 | fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId> { | 44 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
45 | FileLoaderDelegate(self).resolve_path(anchor, relative_path) | 45 | FileLoaderDelegate(self).resolve_path(anchor, path) |
46 | } | 46 | } |
47 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 47 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
48 | FileLoaderDelegate(self).relevant_crates(file_id) | 48 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 43927c991..21a3bdfd1 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -72,8 +72,8 @@ impl FileLoader for TestDB { | |||
72 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 72 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
73 | FileLoaderDelegate(self).file_text(file_id) | 73 | FileLoaderDelegate(self).file_text(file_id) |
74 | } | 74 | } |
75 | fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId> { | 75 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
76 | FileLoaderDelegate(self).resolve_path(anchor, relative_path) | 76 | FileLoaderDelegate(self).resolve_path(anchor, path) |
77 | } | 77 | } |
78 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 78 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
79 | FileLoaderDelegate(self).relevant_crates(file_id) | 79 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 72793d63d..93d5891a0 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -57,8 +57,8 @@ impl FileLoader for RootDatabase { | |||
57 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 57 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
58 | FileLoaderDelegate(self).file_text(file_id) | 58 | FileLoaderDelegate(self).file_text(file_id) |
59 | } | 59 | } |
60 | fn resolve_path(&self, anchor: FileId, relative_path: &RelativePath) -> Option<FileId> { | 60 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
61 | FileLoaderDelegate(self).resolve_path(anchor, relative_path) | 61 | FileLoaderDelegate(self).resolve_path(anchor, path) |
62 | } | 62 | } |
63 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 63 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
64 | FileLoaderDelegate(self).relevant_crates(file_id) | 64 | FileLoaderDelegate(self).relevant_crates(file_id) |