diff options
author | Aleksey Kladov <[email protected]> | 2020-06-05 15:45:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-05 16:22:56 +0100 |
commit | bbb40d746368eb6a38498649a723c7ead0ef8136 (patch) | |
tree | 6496e07d1558ef7b1f8c0cb51648fd44755c8f8e /crates/ra_hir_expand | |
parent | 9c52f527a1cef7d39c2b1c55b49dc5459d392a4d (diff) |
Minimize FileLoader interface
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/test_db.rs | 9 |
2 files changed, 7 insertions, 20 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index eec5fb8eb..7579546d2 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -295,19 +295,13 @@ fn concat_expand( | |||
295 | 295 | ||
296 | fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Option<FileId> { | 296 | fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Option<FileId> { |
297 | let call_site = call_id.as_file().original_file(db); | 297 | let call_site = call_id.as_file().original_file(db); |
298 | 298 | let res = db.resolve_path(call_site, path)?; | |
299 | // Handle trivial case | 299 | // Prevent include itself |
300 | if let Some(res) = db.resolve_path(call_site, path) { | 300 | if res == call_site { |
301 | // Prevent include itself | 301 | None |
302 | return if res == call_site { None } else { Some(res) }; | 302 | } else { |
303 | Some(res) | ||
303 | } | 304 | } |
304 | |||
305 | // Extern paths ? | ||
306 | let krate = *db.relevant_crates(call_site).get(0)?; | ||
307 | let (extern_source_id, relative_file) = | ||
308 | db.crate_graph()[krate].extern_source.extern_path(path)?; | ||
309 | |||
310 | db.resolve_extern_path(extern_source_id, &relative_file) | ||
311 | } | 305 | } |
312 | 306 | ||
313 | fn parse_string(tt: &tt::Subtree) -> Result<String, mbe::ExpandError> { | 307 | fn parse_string(tt: &tt::Subtree) -> Result<String, mbe::ExpandError> { |
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs index 765a2f6d1..fdf225f55 100644 --- a/crates/ra_hir_expand/src/test_db.rs +++ b/crates/ra_hir_expand/src/test_db.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | sync::{Arc, Mutex}, | 5 | sync::{Arc, Mutex}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ra_db::{salsa, CrateId, ExternSourceId, FileId, FileLoader, FileLoaderDelegate, RelativePath}; | 8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; |
9 | 9 | ||
10 | #[salsa::database( | 10 | #[salsa::database( |
11 | ra_db::SourceDatabaseExtStorage, | 11 | ra_db::SourceDatabaseExtStorage, |
@@ -47,11 +47,4 @@ impl FileLoader for TestDB { | |||
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) |
49 | } | 49 | } |
50 | fn resolve_extern_path( | ||
51 | &self, | ||
52 | anchor: ExternSourceId, | ||
53 | relative_path: &RelativePath, | ||
54 | ) -> Option<FileId> { | ||
55 | FileLoaderDelegate(self).resolve_extern_path(anchor, relative_path) | ||
56 | } | ||
57 | } | 50 | } |