Fix showing/hiding copilot actions when disable_ai setting is changed (#35506)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-08-01 22:09:05 -06:00 committed by GitHub
parent 4d79edc753
commit a8422d4f77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -85,45 +85,13 @@ pub fn init(
move |cx| Copilot::start(new_server_id, fs, node_runtime, cx)
});
Copilot::set_global(copilot.clone(), cx);
cx.observe(&copilot, |handle, cx| {
let copilot_action_types = [
TypeId::of::<Suggest>(),
TypeId::of::<NextSuggestion>(),
TypeId::of::<PreviousSuggestion>(),
TypeId::of::<Reinstall>(),
];
let copilot_auth_action_types = [TypeId::of::<SignOut>()];
let copilot_no_auth_action_types = [TypeId::of::<SignIn>()];
let status = handle.read(cx).status();
let is_ai_disabled = DisableAiSettings::get_global(cx).disable_ai;
let filter = CommandPaletteFilter::global_mut(cx);
if is_ai_disabled {
filter.hide_action_types(&copilot_action_types);
filter.hide_action_types(&copilot_auth_action_types);
filter.hide_action_types(&copilot_no_auth_action_types);
} else {
match status {
Status::Disabled => {
filter.hide_action_types(&copilot_action_types);
filter.hide_action_types(&copilot_auth_action_types);
filter.hide_action_types(&copilot_no_auth_action_types);
}
Status::Authorized => {
filter.hide_action_types(&copilot_no_auth_action_types);
filter.show_action_types(
copilot_action_types
.iter()
.chain(&copilot_auth_action_types),
);
}
_ => {
filter.hide_action_types(&copilot_action_types);
filter.hide_action_types(&copilot_auth_action_types);
filter.show_action_types(copilot_no_auth_action_types.iter());
}
}
cx.observe(&copilot, |copilot, cx| {
copilot.update(cx, |copilot, cx| copilot.update_action_visibilities(cx));
})
.detach();
cx.observe_global::<SettingsStore>(|cx| {
if let Some(copilot) = Copilot::global(cx) {
copilot.update(cx, |copilot, cx| copilot.update_action_visibilities(cx));
}
})
.detach();
@ -1131,6 +1099,44 @@ impl Copilot {
cx.notify();
}
}
fn update_action_visibilities(&self, cx: &mut App) {
let signed_in_actions = [
TypeId::of::<Suggest>(),
TypeId::of::<NextSuggestion>(),
TypeId::of::<PreviousSuggestion>(),
TypeId::of::<Reinstall>(),
];
let auth_actions = [TypeId::of::<SignOut>()];
let no_auth_actions = [TypeId::of::<SignIn>()];
let status = self.status();
let is_ai_disabled = DisableAiSettings::get_global(cx).disable_ai;
let filter = CommandPaletteFilter::global_mut(cx);
if is_ai_disabled {
filter.hide_action_types(&signed_in_actions);
filter.hide_action_types(&auth_actions);
filter.hide_action_types(&no_auth_actions);
} else {
match status {
Status::Disabled => {
filter.hide_action_types(&signed_in_actions);
filter.hide_action_types(&auth_actions);
filter.hide_action_types(&no_auth_actions);
}
Status::Authorized => {
filter.hide_action_types(&no_auth_actions);
filter.show_action_types(signed_in_actions.iter().chain(&auth_actions));
}
_ => {
filter.hide_action_types(&signed_in_actions);
filter.hide_action_types(&auth_actions);
filter.show_action_types(no_auth_actions.iter());
}
}
}
}
}
fn id_for_language(language: Option<&Arc<Language>>) -> String {