Skip to content

Commit

Permalink
Fix panic when calculating inline completion (#22180)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrnugget authored Dec 18, 2024
1 parent 6898a31 commit 2469122
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2469122

Please sign in to comment.