assistant panel: Fix entering credentials not updating view (#15527)

Co-authored-by: Bennet <bennet@zed.dev>

Release Notes:

- N/A

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Thorsten Ball
2024-07-31 12:51:41 +02:00
committed by GitHub
co-authored by Bennet
parent c78ea0df7e
commit b571bc800d
10 changed files with 92 additions and 52 deletions
+28 -10
View File
@@ -393,8 +393,13 @@ impl AssistantPanel {
cx.subscribe(&context_store, Self::handle_context_store_event),
cx.subscribe(
&LanguageModelRegistry::global(cx),
|this, _, _: &language_model::ActiveModelChanged, cx| {
this.completion_provider_changed(cx);
|this, _, event: &language_model::Event, cx| match event {
language_model::Event::ActiveModelChanged => {
this.completion_provider_changed(cx);
}
language_model::Event::ProviderStateChanged => {
this.ensure_authenticated(cx);
}
},
),
];
@@ -587,6 +592,16 @@ impl AssistantPanel {
}
fn ensure_authenticated(&mut self, cx: &mut ViewContext<Self>) {
if self.is_authenticated(cx) {
for context_editor in self.context_editors(cx) {
context_editor.update(cx, |editor, cx| {
editor.set_authentication_prompt(None, cx);
});
}
cx.notify();
return;
}
let Some(provider_id) = LanguageModelRegistry::read_global(cx)
.active_provider()
.map(|p| p.id())
@@ -595,15 +610,18 @@ impl AssistantPanel {
};
let load_credentials = self.authenticate(cx);
let task = cx.spawn(|this, mut cx| async move {
let _ = load_credentials.await;
this.update(&mut cx, |this, cx| {
this.show_authentication_prompt(cx);
})
.log_err();
});
self.authenticate_provider_task = Some((provider_id, task));
self.authenticate_provider_task = Some((
provider_id,
cx.spawn(|this, mut cx| async move {
let _ = load_credentials.await;
this.update(&mut cx, |this, cx| {
this.show_authentication_prompt(cx);
this.authenticate_provider_task = None;
})
.log_err();
}),
));
}
fn show_authentication_prompt(&mut self, cx: &mut ViewContext<Self>) {