Fix unrelated panics in tests

This commit is contained in:
Mikayla Maki 2023-03-30 17:19:29 -07:00
parent c3188be4c1
commit e38f52d595

View file

@ -77,6 +77,7 @@ pub struct CopilotButton {
editor_subscription: Option<(Subscription, usize)>, editor_subscription: Option<(Subscription, usize)>,
editor_enabled: Option<bool>, editor_enabled: Option<bool>,
language: Option<Arc<str>>, language: Option<Arc<str>>,
// _settings_subscription: Subscription,
} }
impl Entity for CopilotButton { impl Entity for CopilotButton {
@ -97,7 +98,10 @@ impl View for CopilotButton {
let theme = settings.theme.clone(); let theme = settings.theme.clone();
let active = self.popup_menu.read(cx).visible(); let active = self.popup_menu.read(cx).visible();
let status = Copilot::global(cx).unwrap().read(cx).status(); let Some(copilot) = Copilot::global(cx) else {
return Empty::new().boxed();
};
let status = copilot.read(cx).status();
let enabled = self.editor_enabled.unwrap_or(settings.copilot_on(None)); let enabled = self.editor_enabled.unwrap_or(settings.copilot_on(None));
@ -159,7 +163,8 @@ impl View for CopilotButton {
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
task.await; task.await;
cx.update(|cx| { cx.update(|cx| {
let status = Copilot::global(cx).unwrap().read(cx).status(); if let Some(copilot) = Copilot::global(cx) {
let status = copilot.read(cx).status();
match status { match status {
Status::Authorized => cx.dispatch_action_at( Status::Authorized => cx.dispatch_action_at(
window_id, window_id,
@ -178,6 +183,7 @@ impl View for CopilotButton {
cx.dispatch_global_action(SignIn) cx.dispatch_global_action(SignIn)
} }
} }
}
}) })
}) })
.detach(); .detach();
@ -220,17 +226,20 @@ impl CopilotButton {
}); });
cx.observe(&menu, |_, _, cx| cx.notify()).detach(); cx.observe(&menu, |_, _, cx| cx.notify()).detach();
cx.observe(&Copilot::global(cx).unwrap(), |_, _, cx| cx.notify())
.detach(); Copilot::global(cx).map(|copilot| cx.observe(&copilot, |_, _, cx| cx.notify()).detach());
let this_handle = cx.handle();
cx.observe_global::<Settings, _>(move |cx| this_handle.update(cx, |_, cx| cx.notify())) // TODO: Determine why this leaked.
.detach(); // let this_handle = cx.handle();
// let sub =
// cx.observe_global::<Settings, _>(move |cx| this_handle.update(cx, |_, cx| cx.notify()));
Self { Self {
popup_menu: menu, popup_menu: menu,
editor_subscription: None, editor_subscription: None,
editor_enabled: None, editor_enabled: None,
language: None, language: None,
// _settings_subscription: sub,
} }
} }