From 246912278459118d736106e6f4d1a140435b5708 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 18 Dec 2024 09:53:34 +0100 Subject: [PATCH] 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 --- crates/editor/src/editor.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 8ffac575035a455e36727971b7fd15f9966a99a7..8673e1f6d3222edb8c85fd50accfe59542073110 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -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::>(); if edits.is_empty() {