Fix showing/hiding copilot actions when disable_ai
setting is changed (#35506)
Release Notes: - N/A
This commit is contained in:
parent
4d79edc753
commit
a8422d4f77
1 changed files with 45 additions and 39 deletions
|
@ -85,45 +85,13 @@ pub fn init(
|
||||||
move |cx| Copilot::start(new_server_id, fs, node_runtime, cx)
|
move |cx| Copilot::start(new_server_id, fs, node_runtime, cx)
|
||||||
});
|
});
|
||||||
Copilot::set_global(copilot.clone(), cx);
|
Copilot::set_global(copilot.clone(), cx);
|
||||||
cx.observe(&copilot, |handle, cx| {
|
cx.observe(&copilot, |copilot, cx| {
|
||||||
let copilot_action_types = [
|
copilot.update(cx, |copilot, cx| copilot.update_action_visibilities(cx));
|
||||||
TypeId::of::<Suggest>(),
|
})
|
||||||
TypeId::of::<NextSuggestion>(),
|
.detach();
|
||||||
TypeId::of::<PreviousSuggestion>(),
|
cx.observe_global::<SettingsStore>(|cx| {
|
||||||
TypeId::of::<Reinstall>(),
|
if let Some(copilot) = Copilot::global(cx) {
|
||||||
];
|
copilot.update(cx, |copilot, cx| copilot.update_action_visibilities(cx));
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -1131,6 +1099,44 @@ impl Copilot {
|
||||||
cx.notify();
|
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 {
|
fn id_for_language(language: Option<&Arc<Language>>) -> String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue