From 24685061899a7ed5a0901cb180a57d71df5c38a8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 24 Aug 2023 14:29:05 +0200 Subject: [PATCH] Always clear refactoring text highlights, even if an error occurs --- crates/ai/src/refactor.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/ai/src/refactor.rs b/crates/ai/src/refactor.rs index 82bebeb336f528986575a30a726ae8e9bc804b8b..1cb370dbba1ffd2b16b7b4ba52da21d3663a191b 100644 --- a/crates/ai/src/refactor.rs +++ b/crates/ai/src/refactor.rs @@ -101,6 +101,16 @@ impl RefactoringAssistant { editor.id(), cx.spawn(|mut cx| { async move { + let _clear_highlights = util::defer({ + let mut cx = cx.clone(); + let editor = editor.clone(); + move || { + let _ = editor.update(&mut cx, |editor, cx| { + editor.clear_text_highlights::(cx); + }); + } + }); + let mut edit_start = selection.start.to_offset(&snapshot); let (mut hunks_tx, mut hunks_rx) = mpsc::channel(1); @@ -215,11 +225,7 @@ impl RefactoringAssistant { ); })?; } - diff.await?; - editor.update(&mut cx, |editor, cx| { - editor.clear_text_highlights::(cx); - })?; anyhow::Ok(()) }