zeta2: Do not include empty edit events (#39116)

Bennet Bo Fenner created

Release Notes:

- N/A

Change summary

crates/zeta2/src/zeta2.rs | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

Detailed changes

crates/zeta2/src/zeta2.rs 🔗

@@ -339,7 +339,7 @@ impl Zeta {
                 state
                     .events
                     .iter()
-                    .map(|event| match event {
+                    .filter_map(|event| match event {
                         Event::BufferChange {
                             old_snapshot,
                             new_snapshot,
@@ -356,15 +356,20 @@ impl Zeta {
                                 }
                             });
 
-                            predict_edits_v3::Event::BufferChange {
-                                old_path,
-                                path,
-                                diff: language::unified_diff(
-                                    &old_snapshot.text(),
-                                    &new_snapshot.text(),
-                                ),
-                                //todo: Actually detect if this edit was predicted or not
-                                predicted: false,
+                            // TODO [zeta2] move to bg?
+                            let diff =
+                                language::unified_diff(&old_snapshot.text(), &new_snapshot.text());
+
+                            if path == old_path && diff.is_empty() {
+                                None
+                            } else {
+                                Some(predict_edits_v3::Event::BufferChange {
+                                    old_path,
+                                    path,
+                                    diff,
+                                    //todo: Actually detect if this edit was predicted or not
+                                    predicted: false,
+                                })
                             }
                         }
                     })