Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

copilot: Clear completions upon discard (#40185)

Tim Vermeulen4bc324ccdce1
diff --git a/crates/copilot/src/copilot_edit_prediction_delegate.rs b/crates/copilot/src/copilot_edit_prediction_delegate.rs
index cfb5eef7e08..2d5b387479f 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<Self>) {}
+ fn discard(&mut self, _reason: EditPredictionDiscardReason, _: &mut Context<Self>) {
+ 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");