Fuzzy-match lines when applying edits from the assistant (#12056)

This uses Jaro-Winkler similarity for now, which seemed to produce
pretty good results in my tests. We can easily swap it with something
else if needed.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-05-20 17:02:15 +02:00 committed by GitHub
parent 0b8c1680fb
commit 3a79aa85f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 104 additions and 75 deletions

View file

@ -3058,9 +3058,9 @@ impl ConversationEditor {
.entry(buffer)
.or_insert(Vec::<(Range<language::Anchor>, _)>::new());
for suggestion in suggestions {
let ranges =
fuzzy_search_lines(snapshot.as_rope(), &suggestion.old_text);
if let Some(range) = ranges.first() {
if let Some(range) =
fuzzy_search_lines(snapshot.as_rope(), &suggestion.old_text)
{
let edit_start = snapshot.anchor_after(range.start);
let edit_end = snapshot.anchor_before(range.end);
if let Err(ix) = edits.binary_search_by(|(range, _)| {