edit prediction: Fix crash in `highlight_text` (#23766)
This fixes the panics we we're seeing in `EditPreview::highlight_edits`. The reason for this was that we were interpolating edits incorrectly. Here's an example: ```rust let a = 0; // existing code let c = 2; // suggested by edit prediction ``` The edits would look like this: `[(Point(1, 0)..Point(1, 0), "let c = 2;"]` Now i type: ```rust let a = 0; // existing code let b = 1; // added this line let c = 2; // suggested by edit prediction ``` Before this change, the `interpolate` function would allow insertions before the edit prediction edits, the anchors will move to the next line. The edits would look now like this: `[(Point(2, 0)..Point(2, 0), "let c = 2;"]` However, now we end up with a call to `EditPreview::highlight_edits`, with the following parameters: - current_snapshot: ```rust let a = 0; let b = 1; ``` - edits: `[(Point(2, 0)..Point(2, 0), "let c = 2;"]` - applied_edits_snapshot: ```rust let a = 0; let c = 2; ``` And here you can see the issue, applying the `edits` to the `current_snapshot` should always end up re-creating the text that is present in the `applied_edits_snapshot`. That is not the case here though, meaning that the offsets in the new buffer are not correct, which can either lead to a confusing popup or a crash if the suggestion is at the end of the file. Here's a real world example (edit prediction is ONLY suggesting to delete a new line): <img width="487" alt="Screenshot 2025-01-27 at 13 05 26" src="https://github.com/user-attachments/assets/a0a8064e-8cfa-48b2-9f1c-efc2d0d9d7d4" /> We fixed this by only allowing interpolation if the user is editing after all the edit predictions OR if the user edit is a subset of the model suggestion. Co-Authored-by: Antonio <antonio@zed.dev> Release Notes: - N/A Co-authored-by: Antonio <antonio@zed.dev>
B
Bennet Bo Fenner committed
dfed43ab24ab9cdf41a5645382d46fa67edfcdd9
Parent: b99159c
Committed by GitHub <noreply@github.com>
on 1/28/2025, 11:08:04 AM