From 6e24321e4579d25686982002ed18f321db23cb9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Dec 2020 19:01:15 +0300 Subject: Introduce anchored_path They allow to represent paths like `#[path = "C:\path.rs"] mod foo;` in a lossless cross-platform & network-transparent way. --- crates/hir_def/src/nameres/mod_resolution.rs | 5 +++-- crates/hir_def/src/test_db.rs | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/hir_def/src') 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 @@ //! This module resolves `mod foo;` declaration to file. -use base_db::FileId; +use base_db::{AnchoredPath, FileId}; use hir_expand::name::Name; use syntax::SmolStr; use test_utils::mark; @@ -77,7 +77,8 @@ impl ModDir { }; for candidate in candidate_files.iter() { - if let Some(file_id) = db.resolve_path(file_id, candidate.as_str()) { + let path = AnchoredPath { anchor: file_id, path: candidate.as_str() }; + if let Some(file_id) = db.resolve_path(path) { let is_mod_rs = candidate.ends_with("mod.rs"); 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::{ sync::{Arc, Mutex}, }; -use base_db::SourceDatabase; use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, Upcast}; +use base_db::{AnchoredPath, SourceDatabase}; use hir_expand::db::AstDatabase; use hir_expand::diagnostics::Diagnostic; use hir_expand::diagnostics::DiagnosticSinkBuilder; @@ -63,8 +63,8 @@ impl FileLoader for TestDB { fn file_text(&self, file_id: FileId) -> Arc { FileLoaderDelegate(self).file_text(file_id) } - fn resolve_path(&self, anchor: FileId, path: &str) -> Option { - FileLoaderDelegate(self).resolve_path(anchor, path) + fn resolve_path(&self, path: AnchoredPath) -> Option { + FileLoaderDelegate(self).resolve_path(path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { FileLoaderDelegate(self).relevant_crates(file_id) -- cgit v1.2.3