Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Extract a `SuggestionMap::randomly_mutate` method
Antonio Scandurra3d165f705ffd
diff --git a/crates/editor/src/display_map/suggestion_map.rs b/crates/editor/src/display_map/suggestion_map.rsindex d15ada5f375..49cc64a052c 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::<String>()- .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<SuggestionEdit>) {+ 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::<String>()+ .as_str()+ .into(),+ highlight_style: Default::default(),+ })+ };++ log::info!("replacing suggestion with {:?}", new_suggestion);+ self.replace(new_suggestion, fold_snapshot, Default::default())+ }+ }}