From 4a9989fe384106ec102feacb582f8ac145c9283c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 19 Apr 2023 20:10:57 +0200 Subject: [PATCH] Clear all suggestions from `Editor` when disabling Copilot Co-Authored-By: Nathan Sobo --- crates/editor/src/editor.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 2d39416858..45365b8381 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1265,7 +1265,7 @@ impl Editor { cx.subscribe(&buffer, Self::on_buffer_event), cx.observe(&display_map, Self::on_display_map_changed), cx.observe(&blink_manager, |_, _, cx| cx.notify()), - cx.observe_global::(Self::on_settings_changed), + cx.observe_global::(Self::settings_changed), ], }; this.end_selection(cx); @@ -2808,7 +2808,7 @@ impl Editor { fn refresh_copilot_suggestions(&mut self, cx: &mut ViewContext) -> Option<()> { let copilot = Copilot::global(cx)?; if self.mode != EditorMode::Full || !copilot.read(cx).status().is_authorized() { - self.hide_copilot_suggestion(cx); + self.clear_copilot_suggestions(cx); return None; } self.update_visible_copilot_suggestion(cx); @@ -2820,7 +2820,7 @@ impl Editor { .global::() .show_copilot_suggestions(language_name.as_deref()) { - self.hide_copilot_suggestion(cx); + self.clear_copilot_suggestions(cx); return None; } @@ -2941,6 +2941,11 @@ impl Editor { } } + fn clear_copilot_suggestions(&mut self, cx: &mut ViewContext) { + self.copilot_state = Default::default(); + self.hide_copilot_suggestion(cx); + } + pub fn render_code_actions_indicator( &self, style: &EditorStyle, @@ -6494,7 +6499,7 @@ impl Editor { cx.notify(); } - fn on_settings_changed(&mut self, cx: &mut ViewContext) { + fn settings_changed(&mut self, cx: &mut ViewContext) { self.refresh_copilot_suggestions(cx); }