mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Introduce anchored_path
They allow to represent paths like `#[path = "C:\path.rs"] mod foo;` in a lossless cross-platform & network-transparent way.
This commit is contained in:
parent
5e3891c255
commit
6e24321e45
13 changed files with 79 additions and 65 deletions
|
@ -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() {
|
||||
|
|
|
@ -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<String> {
|
||||
FileLoaderDelegate(self).file_text(file_id)
|
||||
}
|
||||
fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_path(anchor, path)
|
||||
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_path(path)
|
||||
}
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue