Auto merge of #13237 - Veykril:process-changes, r=Veykril
Amalgamate file changes for the same file ids in process_changes When receiving multiple change events for a single file id where the last change is a delete the server panics, as it tries to access the file contents of a deleted file. This occurs due to the VFS changes and the in memory file contents being updated immediately, while `process_changes` processes the events afterwards in sequence which no longer works as it will only observe the final file contents. By folding these events together, we will no longer try to process these intermediate changes, as they aren't relevant anyways. Potentially fixes https://github.com/rust-lang/rust-analyzer/issues/13236
This commit is contained in:
commit
093de32f80
@ -185,11 +185,48 @@ pub(crate) fn process_changes(&mut self) -> bool {
|
|||||||
let (change, changed_files) = {
|
let (change, changed_files) = {
|
||||||
let mut change = Change::new();
|
let mut change = Change::new();
|
||||||
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
||||||
let changed_files = vfs.take_changes();
|
let mut changed_files = vfs.take_changes();
|
||||||
if changed_files.is_empty() {
|
if changed_files.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// important: this needs to be a stable sort, the order between changes is relevant
|
||||||
|
// for the same file ids
|
||||||
|
changed_files.sort_by_key(|file| file.file_id);
|
||||||
|
// We need to fix up the changed events a bit, if we have a create or modify for a file
|
||||||
|
// id that is followed by a delete we actually no longer observe the file text from the
|
||||||
|
// create or modify which may cause problems later on
|
||||||
|
changed_files.dedup_by(|a, b| {
|
||||||
|
use vfs::ChangeKind::*;
|
||||||
|
|
||||||
|
if a.file_id != b.file_id {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
match (a.change_kind, b.change_kind) {
|
||||||
|
// duplicate can be merged
|
||||||
|
(Create, Create) | (Modify, Modify) | (Delete, Delete) => true,
|
||||||
|
// just leave the create, modify is irrelevant
|
||||||
|
(Create, Modify) => {
|
||||||
|
std::mem::swap(a, b);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
// modify becomes irrelevant if the file is deleted
|
||||||
|
(Modify, Delete) => true,
|
||||||
|
// we should fully remove this occurrence,
|
||||||
|
// but leaving just a delete works as well
|
||||||
|
(Create, Delete) => true,
|
||||||
|
// this is equivalent to a modify
|
||||||
|
(Delete, Create) => {
|
||||||
|
a.change_kind = Modify;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
// can't really occur
|
||||||
|
(Modify, Create) => false,
|
||||||
|
(Delete, Modify) => false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for file in &changed_files {
|
for file in &changed_files {
|
||||||
if let Some(path) = vfs.file_path(file.file_id).as_path() {
|
if let Some(path) = vfs.file_path(file.file_id).as_path() {
|
||||||
let path = path.to_path_buf();
|
let path = path.to_path_buf();
|
||||||
|
Loading…
Reference in New Issue
Block a user