diff --git a/crates/editor/src/display_map/suggestion_map.rs b/crates/editor/src/display_map/suggestion_map.rs index d15ada5f375064671132bd9b99f52143cad4dfcb..49cc64a052c360c0eefeb7744fc51603b4c4119a 100644 --- a/crates/editor/src/display_map/suggestion_map.rs +++ b/crates/editor/src/display_map/suggestion_map.rs @@ -635,25 +635,7 @@ mod tests { let mut buffer_edits = Vec::new(); match rng.gen_range(0..=100) { 0..=29 => { - let new_suggestion = if rng.gen_bool(0.3) { - None - } else { - let index = rng.gen_range(0..=buffer_snapshot.len()); - let len = rng.gen_range(0..30); - Some(Suggestion { - position: index, - text: util::RandomCharIter::new(&mut rng) - .take(len) - .collect::() - .as_str() - .into(), - highlight_style: Default::default(), - }) - }; - - log::info!("replacing suggestion with {:?}", new_suggestion); - let (_, edits) = - suggestion_map.replace(new_suggestion, fold_snapshot, Default::default()); + let (_, edits) = suggestion_map.randomly_mutate(&mut rng); suggestion_edits = suggestion_edits.compose(edits); } 30..=59 => { @@ -831,4 +813,28 @@ mod tests { } } } + + impl SuggestionMap { + fn randomly_mutate(&self, rng: &mut impl Rng) -> (SuggestionSnapshot, Vec) { + let fold_snapshot = self.0.lock().fold_snapshot.clone(); + let new_suggestion = if rng.gen_bool(0.3) { + None + } else { + let index = rng.gen_range(0..=fold_snapshot.buffer_snapshot().len()); + let len = rng.gen_range(0..30); + Some(Suggestion { + position: index, + text: util::RandomCharIter::new(rng) + .take(len) + .collect::() + .as_str() + .into(), + highlight_style: Default::default(), + }) + }; + + log::info!("replacing suggestion with {:?}", new_suggestion); + self.replace(new_suggestion, fold_snapshot, Default::default()) + } + } }