From 88e3d87098f2934ae72f46c0a108650ced994e54 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 6 Dec 2021 13:48:07 -0700 Subject: [PATCH] Get randomized test passing on basic excerpt list features Co-Authored-By: Max Brunsfeld --- crates/language/src/excerpt_list.rs | 41 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/crates/language/src/excerpt_list.rs b/crates/language/src/excerpt_list.rs index 0cda89c579..66b052598d 100644 --- a/crates/language/src/excerpt_list.rs +++ b/crates/language/src/excerpt_list.rs @@ -7,7 +7,7 @@ use std::{cmp, iter, ops::Range}; use sum_tree::{Bias, Cursor, SumTree}; use text::{ subscription::{Subscription, Topic}, - Anchor, AnchorRangeExt, Edit, Patch, TextSummary, + Anchor, AnchorRangeExt, Edit, TextSummary, }; use theme::SyntaxTheme; @@ -138,7 +138,7 @@ impl ExcerptList { } excerpts_to_edit.sort_unstable_by_key(|(excerpt_id, _)| *excerpt_id); - let mut patch = Patch::::default(); + let mut edits = Vec::new(); let mut new_excerpts = SumTree::new(); let mut cursor = snapshot.excerpts.cursor::<(ExcerptId, usize)>(); @@ -156,21 +156,22 @@ impl ExcerptList { &(), ); - let edits = buffer - .edits_since_in_range::( - old_excerpt.buffer.version(), - old_excerpt.range.clone(), - ) - .map(|mut edit| { - let excerpt_old_start = cursor.start().1; - let excerpt_new_start = new_excerpts.summary().text.bytes; - edit.old.start += excerpt_old_start; - edit.old.end += excerpt_old_start; - edit.new.start += excerpt_new_start; - edit.new.end += excerpt_new_start; - edit - }); - patch = patch.compose(edits); + edits.extend( + buffer + .edits_since_in_range::( + old_excerpt.buffer.version(), + old_excerpt.range.clone(), + ) + .map(|mut edit| { + let excerpt_old_start = cursor.start().1; + let excerpt_new_start = new_excerpts.summary().text.bytes; + edit.old.start += excerpt_old_start; + edit.old.end += excerpt_old_start; + edit.new.start += excerpt_new_start; + edit.new.end += excerpt_new_start; + edit + }), + ); cursor.next(&()); } @@ -179,7 +180,7 @@ impl ExcerptList { drop(cursor); snapshot.excerpts = new_excerpts; - self.subscriptions.publish(&patch); + self.subscriptions.publish(edits); } } @@ -382,7 +383,7 @@ mod tests { let buffer_1 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'a'), cx)); let buffer_2 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'g'), cx)); - let list = cx.add_model(|cx| ExcerptList::new()); + let list = cx.add_model(|_| ExcerptList::new()); let subscription = list.update(cx, |list, cx| { let subscription = list.subscribe(); @@ -485,7 +486,7 @@ mod tests { } #[gpui::test(iterations = 100)] - fn test_random(cx: &mut MutableAppContext, mut rng: StdRng) { + fn test_random_excerpts(cx: &mut MutableAppContext, mut rng: StdRng) { let operations = env::var("OPERATIONS") .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) .unwrap_or(10);