ensure renames happen after edit

This commit is contained in:
Pascal Kuthe 2023-11-10 17:39:32 +01:00
parent 7059ae2fc2
commit 0647b645cd
No known key found for this signature in database
GPG key ID: D715E8655AE166A6
2 changed files with 44 additions and 5 deletions

View file

@ -1,7 +1,7 @@
//! Conversion of rust-analyzer specific types to lsp_types equivalents.
use std::{
iter::once,
path,
mem, path,
sync::atomic::{AtomicU32, Ordering},
};
@ -1123,13 +1123,20 @@ pub(crate) fn snippet_text_document_ops(
pub(crate) fn snippet_workspace_edit(
snap: &GlobalStateSnapshot,
source_change: SourceChange,
mut source_change: SourceChange,
) -> Cancellable<lsp_ext::SnippetWorkspaceEdit> {
let mut document_changes: Vec<lsp_ext::SnippetDocumentChangeOperation> = Vec::new();
for op in source_change.file_system_edits {
let ops = snippet_text_document_ops(snap, op)?;
document_changes.extend_from_slice(&ops);
for op in &mut source_change.file_system_edits {
if let FileSystemEdit::CreateFile { dst, initial_contents } = op {
// replace with a placeholder to avoid cloneing the edit
let op = FileSystemEdit::CreateFile {
dst: dst.clone(),
initial_contents: mem::take(initial_contents),
};
let ops = snippet_text_document_ops(snap, op)?;
document_changes.extend_from_slice(&ops);
}
}
for (file_id, (edit, snippet_edit)) in source_change.source_file_edits {
let edit = snippet_text_document_edit(
@ -1141,6 +1148,12 @@ pub(crate) fn snippet_workspace_edit(
)?;
document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit));
}
for op in source_change.file_system_edits {
if !matches!(op, FileSystemEdit::CreateFile { .. }) {
let ops = snippet_text_document_ops(snap, op)?;
document_changes.extend_from_slice(&ops);
}
}
let mut workspace_edit = lsp_ext::SnippetWorkspaceEdit {
changes: None,
document_changes: Some(document_changes),

View file

@ -984,6 +984,11 @@ fn main() {}
//- /src/old_file.rs
//- /src/old_folder/mod.rs
mod nested;
//- /src/old_folder/nested.rs
struct foo;
use crate::old_folder::nested::foo as bar;
//- /src/from_mod/mod.rs
@ -1080,6 +1085,27 @@ fn main() {}
"newText": "new_folder"
}
]
},
{
"textDocument": {
"uri": format!("file://{}", tmp_dir_path.join("src").join("old_folder").join("nested.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace('\\', "/")),
"version": null
},
"edits": [
{
"range": {
"start": {
"line": 1,
"character": 11
},
"end": {
"line": 1,
"character": 21
}
},
"newText": "new_folder"
}
]
}
]
}),