acp: Use unstaged style for diffs (#36674)

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2025-08-21 12:59:51 +02:00 committed by GitHub
parent c5ee3f3e2e
commit f435af2fde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,12 +28,7 @@ impl Diff {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
let multibuffer = cx.new(|_cx| MultiBuffer::without_headers(Capability::ReadOnly)); let multibuffer = cx.new(|_cx| MultiBuffer::without_headers(Capability::ReadOnly));
let buffer = cx.new(|cx| Buffer::local(new_text, cx));
let new_buffer = cx.new(|cx| Buffer::local(new_text, cx));
let old_buffer = cx.new(|cx| Buffer::local(old_text.unwrap_or("".into()), cx));
let new_buffer_snapshot = new_buffer.read(cx).text_snapshot();
let buffer_diff = cx.new(|cx| BufferDiff::new(&new_buffer_snapshot, cx));
let task = cx.spawn({ let task = cx.spawn({
let multibuffer = multibuffer.clone(); let multibuffer = multibuffer.clone();
let path = path.clone(); let path = path.clone();
@ -43,42 +38,34 @@ impl Diff {
.await .await
.log_err(); .log_err();
new_buffer.update(cx, |buffer, cx| buffer.set_language(language.clone(), cx))?; buffer.update(cx, |buffer, cx| buffer.set_language(language.clone(), cx))?;
let old_buffer_snapshot = old_buffer.update(cx, |buffer, cx| { let diff = build_buffer_diff(
buffer.set_language(language, cx); old_text.unwrap_or("".into()).into(),
buffer.snapshot() &buffer,
})?; Some(language_registry.clone()),
cx,
buffer_diff )
.update(cx, |diff, cx| { .await?;
diff.set_base_text(
old_buffer_snapshot,
Some(language_registry),
new_buffer_snapshot,
cx,
)
})?
.await?;
multibuffer multibuffer
.update(cx, |multibuffer, cx| { .update(cx, |multibuffer, cx| {
let hunk_ranges = { let hunk_ranges = {
let buffer = new_buffer.read(cx); let buffer = buffer.read(cx);
let diff = buffer_diff.read(cx); let diff = diff.read(cx);
diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, buffer, cx) diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, buffer, cx)
.map(|diff_hunk| diff_hunk.buffer_range.to_point(buffer)) .map(|diff_hunk| diff_hunk.buffer_range.to_point(buffer))
.collect::<Vec<_>>() .collect::<Vec<_>>()
}; };
multibuffer.set_excerpts_for_path( multibuffer.set_excerpts_for_path(
PathKey::for_buffer(&new_buffer, cx), PathKey::for_buffer(&buffer, cx),
new_buffer.clone(), buffer.clone(),
hunk_ranges, hunk_ranges,
editor::DEFAULT_MULTIBUFFER_CONTEXT, editor::DEFAULT_MULTIBUFFER_CONTEXT,
cx, cx,
); );
multibuffer.add_diff(buffer_diff, cx); multibuffer.add_diff(diff, cx);
}) })
.log_err(); .log_err();
@ -106,6 +93,15 @@ impl Diff {
text_snapshot, text_snapshot,
cx, cx,
); );
let snapshot = diff.snapshot(cx);
let secondary_diff = cx.new(|cx| {
let mut diff = BufferDiff::new(&buffer_snapshot, cx);
diff.set_snapshot(snapshot, &buffer_snapshot, cx);
diff
});
diff.set_secondary_diff(secondary_diff);
diff diff
}); });
@ -204,7 +200,10 @@ impl PendingDiff {
) )
.await?; .await?;
buffer_diff.update(cx, |diff, cx| { buffer_diff.update(cx, |diff, cx| {
diff.set_snapshot(diff_snapshot, &text_snapshot, cx) diff.set_snapshot(diff_snapshot.clone(), &text_snapshot, cx);
diff.secondary_diff().unwrap().update(cx, |diff, cx| {
diff.set_snapshot(diff_snapshot.clone(), &text_snapshot, cx);
});
})?; })?;
diff.update(cx, |diff, cx| { diff.update(cx, |diff, cx| {
if let Diff::Pending(diff) = diff { if let Diff::Pending(diff) = diff {