Fix panic when calculating inline completion (#22180)

Possible panic here in case we can't find the excerpt in the
multibuffer.

I thought this could happen when the inline completion references an
excerpt that disappeared from the multibuffer, but looking at the code
I'm not sure anymore - we use the same multibuffer snapshot in this
whole function and the `anchor_in_excerpt` method clips the anchors.

Still, let's be safe here.

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-12-18 09:53:34 +01:00 committed by GitHub
parent 6898a31f06
commit 2469122784
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4737,16 +4737,10 @@ impl Editor {
let edits = completion
.edits
.into_iter()
.map(|(range, new_text)| {
(
multibuffer
.anchor_in_excerpt(excerpt_id, range.start)
.unwrap()
..multibuffer
.anchor_in_excerpt(excerpt_id, range.end)
.unwrap(),
new_text,
)
.flat_map(|(range, new_text)| {
let start = multibuffer.anchor_in_excerpt(excerpt_id, range.start)?;
let end = multibuffer.anchor_in_excerpt(excerpt_id, range.end)?;
Some((start..end, new_text))
})
.collect::<Vec<_>>();
if edits.is_empty() {