mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +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
|
@ -13,6 +13,7 @@ use lsp_types::{SemanticTokens, Url};
|
|||
use parking_lot::{Mutex, RwLock};
|
||||
use project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
|
||||
use rustc_hash::FxHashMap;
|
||||
use vfs::AnchoredPathBuf;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
|
@ -268,10 +269,10 @@ impl GlobalStateSnapshot {
|
|||
Some(self.mem_docs.get(&path)?.version)
|
||||
}
|
||||
|
||||
pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url {
|
||||
let mut base = self.vfs.read().0.file_path(file_id);
|
||||
pub(crate) fn anchored_path(&self, path: &AnchoredPathBuf) -> Url {
|
||||
let mut base = self.vfs.read().0.file_path(path.anchor);
|
||||
base.pop();
|
||||
let path = base.join(path).unwrap();
|
||||
let path = base.join(&path.path).unwrap();
|
||||
let path = path.as_path().unwrap();
|
||||
url_from_abs_path(&path)
|
||||
}
|
||||
|
|
|
@ -628,17 +628,17 @@ pub(crate) fn resource_op(
|
|||
file_system_edit: FileSystemEdit,
|
||||
) -> lsp_types::ResourceOp {
|
||||
match file_system_edit {
|
||||
FileSystemEdit::CreateFile { anchor, dst } => {
|
||||
let uri = snap.anchored_path(anchor, &dst);
|
||||
FileSystemEdit::CreateFile { dst } => {
|
||||
let uri = snap.anchored_path(&dst);
|
||||
lsp_types::ResourceOp::Create(lsp_types::CreateFile {
|
||||
uri,
|
||||
options: None,
|
||||
annotation: None,
|
||||
})
|
||||
}
|
||||
FileSystemEdit::MoveFile { src, anchor, dst } => {
|
||||
FileSystemEdit::MoveFile { src, dst } => {
|
||||
let old_uri = snap.file_id_to_url(src);
|
||||
let new_uri = snap.anchored_path(anchor, &dst);
|
||||
let new_uri = snap.anchored_path(&dst);
|
||||
lsp_types::ResourceOp::Rename(lsp_types::RenameFile {
|
||||
old_uri,
|
||||
new_uri,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue