Fix missing hunks in project diff after revert (#25906)
Release Notes: - N/A
This commit is contained in:
parent
b774a4b8d1
commit
9e2b7bc5dc
5 changed files with 158 additions and 11 deletions
|
@ -2160,6 +2160,7 @@ impl ReferenceMultibuffer {
|
|||
.unwrap();
|
||||
let excerpt = self.excerpts.remove(ix);
|
||||
let buffer = excerpt.buffer.read(cx);
|
||||
let id = buffer.remote_id();
|
||||
log::info!(
|
||||
"Removing excerpt {}: {:?}",
|
||||
ix,
|
||||
|
@ -2167,6 +2168,13 @@ impl ReferenceMultibuffer {
|
|||
.text_for_range(excerpt.range.to_offset(buffer))
|
||||
.collect::<String>(),
|
||||
);
|
||||
if !self
|
||||
.excerpts
|
||||
.iter()
|
||||
.any(|excerpt| excerpt.buffer.read(cx).remote_id() == id)
|
||||
{
|
||||
self.diffs.remove(&id);
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_excerpt_after(
|
||||
|
@ -2415,6 +2423,7 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
.unwrap_or(10);
|
||||
|
||||
let mut buffers: Vec<Entity<Buffer>> = Vec::new();
|
||||
let mut base_texts: HashMap<BufferId, String> = HashMap::default();
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let mut reference = ReferenceMultibuffer::default();
|
||||
let mut anchors = Vec::new();
|
||||
|
@ -2522,9 +2531,10 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
..snapshot.anchor_in_excerpt(excerpt.id, end).unwrap();
|
||||
|
||||
log::info!(
|
||||
"expanding diff hunks in range {:?} (excerpt id {:?}) index {excerpt_ix:?})",
|
||||
"expanding diff hunks in range {:?} (excerpt id {:?}, index {excerpt_ix:?}, buffer id {:?})",
|
||||
range.to_offset(&snapshot),
|
||||
excerpt.id
|
||||
excerpt.id,
|
||||
excerpt.buffer.read(cx).remote_id(),
|
||||
);
|
||||
reference.expand_diff_hunks(excerpt.id, start..end, cx);
|
||||
multibuffer.expand_diff_hunks(vec![range], cx);
|
||||
|
@ -2534,7 +2544,7 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
for buffer in multibuffer.all_buffers() {
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
let _ = multibuffer.diff_for(snapshot.remote_id()).unwrap().update(
|
||||
multibuffer.diff_for(snapshot.remote_id()).unwrap().update(
|
||||
cx,
|
||||
|diff, cx| {
|
||||
log::info!(
|
||||
|
@ -2551,17 +2561,16 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
}
|
||||
_ => {
|
||||
let buffer_handle = if buffers.is_empty() || rng.gen_bool(0.4) {
|
||||
let base_text = util::RandomCharIter::new(&mut rng)
|
||||
let mut base_text = util::RandomCharIter::new(&mut rng)
|
||||
.take(256)
|
||||
.collect::<String>();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(base_text.clone(), cx));
|
||||
let diff = cx.new(|cx| BufferDiff::new_with_base_text(&base_text, &buffer, cx));
|
||||
|
||||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
reference.add_diff(diff.clone(), cx);
|
||||
multibuffer.add_diff(diff, cx)
|
||||
});
|
||||
text::LineEnding::normalize(&mut base_text);
|
||||
base_texts.insert(
|
||||
buffer.read_with(cx, |buffer, _| buffer.remote_id()),
|
||||
base_text,
|
||||
);
|
||||
buffers.push(buffer);
|
||||
buffers.last().unwrap()
|
||||
} else {
|
||||
|
@ -2595,6 +2604,18 @@ async fn test_random_multibuffer(cx: &mut TestAppContext, mut rng: StdRng) {
|
|||
(start_ix..end_ix, anchor_range)
|
||||
});
|
||||
|
||||
multibuffer.update(cx, |multibuffer, cx| {
|
||||
let id = buffer_handle.read(cx).remote_id();
|
||||
if multibuffer.diff_for(id).is_none() {
|
||||
let base_text = base_texts.get(&id).unwrap();
|
||||
let diff = cx.new(|cx| {
|
||||
BufferDiff::new_with_base_text(base_text, &buffer_handle, cx)
|
||||
});
|
||||
reference.add_diff(diff.clone(), cx);
|
||||
multibuffer.add_diff(diff, cx)
|
||||
}
|
||||
});
|
||||
|
||||
let excerpt_id = multibuffer.update(cx, |multibuffer, cx| {
|
||||
multibuffer
|
||||
.insert_excerpts_after(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue