From 294892c470d76f74e110f4e2fb77d99f23b2ce1d Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Mon, 5 Aug 2024 15:36:08 +0200 Subject: [PATCH] assist panel: Update Zed AI notice if provider changes (#15805) Release Notes: - N/A --------- Co-authored-by: Bennet --- crates/assistant/src/assistant_panel.rs | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 5a31199312..d04ae6e3b7 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -146,6 +146,7 @@ pub struct AssistantPanel { model_summary_editor: View, authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>, configuration_subscription: Option, + client_status: Option, watch_client_status: Option>, show_zed_ai_notice: bool, } @@ -435,6 +436,7 @@ impl AssistantPanel { model_summary_editor, authenticate_provider_task: None, configuration_subscription: None, + client_status: None, watch_client_status: Some(watch_client_status), show_zed_ai_notice: false, }; @@ -446,18 +448,18 @@ impl AssistantPanel { let mut status_rx = client.status(); cx.spawn(|this, mut cx| async move { - let mut old_status = None; while let Some(status) = status_rx.next().await { - if old_status.is_none() - || old_status.map_or(false, |old_status| old_status != status) - { - this.update(&mut cx, |this, cx| { - this.handle_client_status_change(status, cx) - }) - .log_err(); - - old_status = Some(status); - } + this.update(&mut cx, |this, cx| { + if this.client_status.is_none() + || this + .client_status + .map_or(false, |old_status| old_status != status) + { + this.update_zed_ai_notice_visibility(status, cx); + } + this.client_status = Some(status); + }) + .log_err(); } this.update(&mut cx, |this, _cx| this.watch_client_status = None) .log_err(); @@ -554,7 +556,11 @@ impl AssistantPanel { } } - fn handle_client_status_change(&mut self, client_status: Status, cx: &mut ViewContext) { + fn update_zed_ai_notice_visibility( + &mut self, + client_status: Status, + cx: &mut ViewContext, + ) { let active_provider = LanguageModelRegistry::read_global(cx).active_provider(); // If we're signed out and don't have a provider configured, or we're signed-out AND Zed.dev is @@ -642,6 +648,10 @@ impl AssistantPanel { self.authenticate_provider_task = None; self.ensure_authenticated(cx); } + + if let Some(status) = self.client_status { + self.update_zed_ai_notice_visibility(status, cx); + } } fn ensure_authenticated(&mut self, cx: &mut ViewContext) {