Project level git diff recalc handling

This avoids an issue where in a many-buffer multi-buffer, each modified
buffer could complete its recalc independently, causing a cascade of
repeated notifies

Now all recalcs started at the same time must complete before
 A: Starting another recalc pass
 B: The master notify occurring

Each buffer can still show its new diff if something else triggers it
to notify earlier, this is desirable and does not have the same negative
effects as the notify cascade as those re-layouts would need to happen
anyway

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Julia 2023-05-18 18:25:58 -04:00
parent 54421b11f3
commit cede296b04
4 changed files with 64 additions and 37 deletions

View file

@ -682,21 +682,29 @@ impl Buffer {
self.git_diff_status.diff.needs_update(self)
}
fn git_diff_recalc_2(&mut self, cx: &mut ModelContext<Self>) -> Option<Task<()>> {
let diff_base = &self.diff_base?;
pub fn git_diff_recalc_2(&mut self, cx: &mut ModelContext<Self>) -> Option<Task<()>> {
let diff_base = self.diff_base.clone()?; // TODO: Make this an Arc
let snapshot = self.snapshot();
let handle = cx.weak_handle();
let mut diff = self.git_diff_status.diff.clone();
Some(cx.background().spawn(async move {
let diff = cx.background().spawn(async move {
diff.update(&diff_base, &snapshot).await;
if let Some(this) = handle.upgrade(cx) {
// this.update(cx)
diff
});
let handle = cx.weak_handle();
Some(cx.spawn_weak(|_, mut cx| async move {
let buffer_diff = diff.await;
if let Some(this) = handle.upgrade(&mut cx) {
this.update(&mut cx, |this, _| {
this.git_diff_status.diff = buffer_diff;
this.git_diff_update_count += 1;
})
}
}))
}
pub fn git_diff_recalc(&mut self, cx: &mut ModelContext<Self>) {
fn git_diff_recalc(&mut self, cx: &mut ModelContext<Self>) {
if self.git_diff_status.update_in_progress {
self.git_diff_status.update_requested = true;
return;