aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-09 16:01:15 +0000
committerAleksey Kladov <[email protected]>2020-12-09 16:07:05 +0000
commit6e24321e4579d25686982002ed18f321db23cb9f (patch)
tree08f0fd7d99ad22a3d1db782482b66548e99ba8b2 /crates/hir_def
parent5e3891c2559de5a6540d69bc14ded281484479f9 (diff)
Introduce anchored_path
They allow to represent paths like `#[path = "C:\path.rs"] mod foo;` in a lossless cross-platform & network-transparent way.
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/nameres/mod_resolution.rs5
-rw-r--r--crates/hir_def/src/test_db.rs6
2 files changed, 6 insertions, 5 deletions
diff --git a/crates/hir_def/src/nameres/mod_resolution.rs b/crates/hir_def/src/nameres/mod_resolution.rs
index c0c789cae..b4ccd4488 100644
--- a/crates/hir_def/src/nameres/mod_resolution.rs
+++ b/crates/hir_def/src/nameres/mod_resolution.rs
@@ -1,5 +1,5 @@
1//! This module resolves `mod foo;` declaration to file. 1//! This module resolves `mod foo;` declaration to file.
2use base_db::FileId; 2use base_db::{AnchoredPath, FileId};
3use hir_expand::name::Name; 3use hir_expand::name::Name;
4use syntax::SmolStr; 4use syntax::SmolStr;
5use test_utils::mark; 5use test_utils::mark;
@@ -77,7 +77,8 @@ impl ModDir {
77 }; 77 };
78 78
79 for candidate in candidate_files.iter() { 79 for candidate in candidate_files.iter() {
80 if let Some(file_id) = db.resolve_path(file_id, candidate.as_str()) { 80 let path = AnchoredPath { anchor: file_id, path: candidate.as_str() };
81 if let Some(file_id) = db.resolve_path(path) {
81 let is_mod_rs = candidate.ends_with("mod.rs"); 82 let is_mod_rs = candidate.ends_with("mod.rs");
82 83
83 let (dir_path, root_non_dir_owner) = if is_mod_rs || attr_path.is_some() { 84 let (dir_path, root_non_dir_owner) = if is_mod_rs || attr_path.is_some() {
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs
index f8b150850..574c0201a 100644
--- a/crates/hir_def/src/test_db.rs
+++ b/crates/hir_def/src/test_db.rs
@@ -5,8 +5,8 @@ use std::{
5 sync::{Arc, Mutex}, 5 sync::{Arc, Mutex},
6}; 6};
7 7
8use base_db::SourceDatabase;
9use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, Upcast}; 8use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, Upcast};
9use base_db::{AnchoredPath, SourceDatabase};
10use hir_expand::db::AstDatabase; 10use hir_expand::db::AstDatabase;
11use hir_expand::diagnostics::Diagnostic; 11use hir_expand::diagnostics::Diagnostic;
12use hir_expand::diagnostics::DiagnosticSinkBuilder; 12use hir_expand::diagnostics::DiagnosticSinkBuilder;
@@ -63,8 +63,8 @@ impl FileLoader for TestDB {
63 fn file_text(&self, file_id: FileId) -> Arc<String> { 63 fn file_text(&self, file_id: FileId) -> Arc<String> {
64 FileLoaderDelegate(self).file_text(file_id) 64 FileLoaderDelegate(self).file_text(file_id)
65 } 65 }
66 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 66 fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
67 FileLoaderDelegate(self).resolve_path(anchor, path) 67 FileLoaderDelegate(self).resolve_path(path)
68 } 68 }
69 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 69 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
70 FileLoaderDelegate(self).relevant_crates(file_id) 70 FileLoaderDelegate(self).relevant_crates(file_id)