mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Extract a SuggestionMap::randomly_mutate
method
This commit is contained in:
parent
35830a0271
commit
3d165f705f
@ -635,25 +635,7 @@ mod tests {
|
|||||||
let mut buffer_edits = Vec::new();
|
let mut buffer_edits = Vec::new();
|
||||||
match rng.gen_range(0..=100) {
|
match rng.gen_range(0..=100) {
|
||||||
0..=29 => {
|
0..=29 => {
|
||||||
let new_suggestion = if rng.gen_bool(0.3) {
|
let (_, edits) = suggestion_map.randomly_mutate(&mut rng);
|
||||||
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());
|
|
||||||
suggestion_edits = suggestion_edits.compose(edits);
|
suggestion_edits = suggestion_edits.compose(edits);
|
||||||
}
|
}
|
||||||
30..=59 => {
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user