about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-13 19:21:30 +0000
committerbors <bors@rust-lang.org>2023-05-13 19:21:30 +0000
commitcbd14e98403dc5e19f19fdf913808656d81a0516 (patch)
tree1042d042dd7aaae735f8345f761adbc847f981cb
parentdaa03b0b0be6bd51dd43f4556dd4e27649bc6f57 (diff)
parentcace5bb35d6c1d949acbfd57b196cd723f0cbf78 (diff)
downloadrust-cbd14e98403dc5e19f19fdf913808656d81a0516.tar.gz
rust-cbd14e98403dc5e19f19fdf913808656d81a0516.zip
Auto merge of #14801 - Veykril:process-changes-fix, r=Veykril
fix: Fix process-changes duplicating change events

Should fix https://github.com/rust-lang/rust-analyzer/issues/14791
-rw-r--r--crates/rust-analyzer/src/global_state.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 9535d88454f..08431d64882 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -196,7 +196,7 @@ impl GlobalState {
         let (change, changed_files) = {
             let mut change = Change::new();
             let (vfs, line_endings_map) = &mut *self.vfs.write();
-            let mut changed_files = vfs.take_changes();
+            let changed_files = vfs.take_changes();
             if changed_files.is_empty() {
                 return false;
             }
@@ -204,7 +204,7 @@ impl GlobalState {
             // 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 skip observing the file text from the
             // earlier event, to avoid problems later on.
-            for changed_file in &changed_files {
+            for changed_file in changed_files {
                 use vfs::ChangeKind::*;
 
                 file_changes
@@ -240,14 +240,13 @@ impl GlobalState {
                     ));
             }
 
-            changed_files.extend(
-                file_changes
-                    .into_iter()
-                    .filter(|(_, (change_kind, just_created))| {
-                        !matches!((change_kind, just_created), (vfs::ChangeKind::Delete, true))
-                    })
-                    .map(|(file_id, (change_kind, _))| vfs::ChangedFile { file_id, change_kind }),
-            );
+            let changed_files: Vec<_> = file_changes
+                .into_iter()
+                .filter(|(_, (change_kind, just_created))| {
+                    !matches!((change_kind, just_created), (vfs::ChangeKind::Delete, true))
+                })
+                .map(|(file_id, (change_kind, _))| vfs::ChangedFile { file_id, change_kind })
+                .collect();
 
             // A file was added or deleted
             let mut has_structure_changes = false;