diff --git a/crates/copilot/src/copilot_edit_prediction_delegate.rs b/crates/copilot/src/copilot_edit_prediction_delegate.rs index cfb5eef7e08caab8fec624a1cf364eecac16ec9b..2d5b387479f380f66519a07468a88929d1c5cc55 100644 --- a/crates/copilot/src/copilot_edit_prediction_delegate.rs +++ b/crates/copilot/src/copilot_edit_prediction_delegate.rs @@ -129,7 +129,9 @@ impl EditPredictionDelegate for CopilotEditPredictionDelegate { } } - fn discard(&mut self, _reason: EditPredictionDiscardReason, _: &mut Context) {} + fn discard(&mut self, _reason: EditPredictionDiscardReason, _: &mut Context) { + self.completion.take(); + } fn suggest( &mut self, @@ -410,8 +412,14 @@ mod tests { assert_eq!(editor.display_text(cx), "one.c \ntwo\nthree\n"); assert_eq!(editor.text(cx), "one.c \ntwo\nthree\n"); - // When undoing the previously active suggestion is shown again. + // When undoing the previously active suggestion isn't shown again. editor.undo(&Default::default(), window, cx); + assert!(!editor.has_active_edit_prediction()); + assert_eq!(editor.display_text(cx), "one.c\ntwo\nthree\n"); + assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n"); + }); + executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT); + cx.editor(|editor, _, cx| { assert!(editor.has_active_edit_prediction()); assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n"); assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");