Anchor file-system operations to the file, and not to the source root.

Anchoring to the SourceRoot wont' work if the path is absolute:

  #[path = "/tmp/foo.rs"]
  mod foo;

Anchoring to a file will.

However, we *should* anchor, instead of just producing an abs path.

I can imagine a situation where, for example, rust-analyzer processes
crates from different machines (or, for example, from in-memory git
branch), where the same absolute path in different crates might refer
to different files in the end!
This commit is contained in:
Aleksey Kladov
2020-06-16 18:45:58 +02:00
parent da34d630b8
commit 3c72fc0573
8 changed files with 67 additions and 81 deletions

View File

@@ -528,13 +528,13 @@ pub(crate) fn resource_op(
file_system_edit: FileSystemEdit,
) -> lsp_types::ResourceOp {
match file_system_edit {
FileSystemEdit::CreateFile { source_root, path } => {
let uri = snap.path_to_url(source_root, &path);
FileSystemEdit::CreateFile { anchor, dst } => {
let uri = snap.anchored_path(anchor, &dst);
lsp_types::ResourceOp::Create(lsp_types::CreateFile { uri, options: None })
}
FileSystemEdit::MoveFile { src, dst_source_root, dst_path } => {
FileSystemEdit::MoveFile { src, anchor, dst } => {
let old_uri = snap.file_id_to_url(src);
let new_uri = snap.path_to_url(dst_source_root, &dst_path);
let new_uri = snap.anchored_path(anchor, &dst);
lsp_types::ResourceOp::Rename(lsp_types::RenameFile { old_uri, new_uri, options: None })
}
}