assist panel: Update Zed AI notice if provider changes (#15805)
Release Notes: - N/A --------- Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
parent
49d0672cdd
commit
294892c470
1 changed files with 22 additions and 12 deletions
|
@ -146,6 +146,7 @@ pub struct AssistantPanel {
|
||||||
model_summary_editor: View<Editor>,
|
model_summary_editor: View<Editor>,
|
||||||
authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>,
|
authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>,
|
||||||
configuration_subscription: Option<Subscription>,
|
configuration_subscription: Option<Subscription>,
|
||||||
|
client_status: Option<client::Status>,
|
||||||
watch_client_status: Option<Task<()>>,
|
watch_client_status: Option<Task<()>>,
|
||||||
show_zed_ai_notice: bool,
|
show_zed_ai_notice: bool,
|
||||||
}
|
}
|
||||||
|
@ -435,6 +436,7 @@ impl AssistantPanel {
|
||||||
model_summary_editor,
|
model_summary_editor,
|
||||||
authenticate_provider_task: None,
|
authenticate_provider_task: None,
|
||||||
configuration_subscription: None,
|
configuration_subscription: None,
|
||||||
|
client_status: None,
|
||||||
watch_client_status: Some(watch_client_status),
|
watch_client_status: Some(watch_client_status),
|
||||||
show_zed_ai_notice: false,
|
show_zed_ai_notice: false,
|
||||||
};
|
};
|
||||||
|
@ -446,18 +448,18 @@ impl AssistantPanel {
|
||||||
let mut status_rx = client.status();
|
let mut status_rx = client.status();
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let mut old_status = None;
|
|
||||||
while let Some(status) = status_rx.next().await {
|
while let Some(status) = status_rx.next().await {
|
||||||
if old_status.is_none()
|
this.update(&mut cx, |this, cx| {
|
||||||
|| old_status.map_or(false, |old_status| old_status != status)
|
if this.client_status.is_none()
|
||||||
{
|
|| this
|
||||||
this.update(&mut cx, |this, cx| {
|
.client_status
|
||||||
this.handle_client_status_change(status, cx)
|
.map_or(false, |old_status| old_status != status)
|
||||||
})
|
{
|
||||||
.log_err();
|
this.update_zed_ai_notice_visibility(status, cx);
|
||||||
|
}
|
||||||
old_status = Some(status);
|
this.client_status = Some(status);
|
||||||
}
|
})
|
||||||
|
.log_err();
|
||||||
}
|
}
|
||||||
this.update(&mut cx, |this, _cx| this.watch_client_status = None)
|
this.update(&mut cx, |this, _cx| this.watch_client_status = None)
|
||||||
.log_err();
|
.log_err();
|
||||||
|
@ -554,7 +556,11 @@ impl AssistantPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_client_status_change(&mut self, client_status: Status, cx: &mut ViewContext<Self>) {
|
fn update_zed_ai_notice_visibility(
|
||||||
|
&mut self,
|
||||||
|
client_status: Status,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
let active_provider = LanguageModelRegistry::read_global(cx).active_provider();
|
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
|
// 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.authenticate_provider_task = None;
|
||||||
self.ensure_authenticated(cx);
|
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<Self>) {
|
fn ensure_authenticated(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue