Barebones Copilot prompt

Filter out sign in/sign out when user is signed in/not signed in
This commit is contained in:
Piotr Osiewicz 2023-12-06 14:14:18 +01:00
parent 3f9fe58c48
commit 7998e8281c
2 changed files with 70 additions and 33 deletions

View file

@ -60,8 +60,8 @@ pub fn init(
TypeId::of::<PreviousSuggestion>(),
TypeId::of::<Reinstall>(),
];
let copilot_auth_action_types = [TypeId::of::<SignIn>(), TypeId::of::<SignOut>()];
let copilot_auth_action_types = [TypeId::of::<SignOut>()];
let copilot_no_auth_action_types = [TypeId::of::<SignIn>()];
let status = handle.read(cx).status();
let filter = cx.default_global::<collections::CommandPaletteFilter>();
@ -69,8 +69,14 @@ pub fn init(
Status::Disabled => {
filter.hidden_action_types.extend(copilot_action_types);
filter.hidden_action_types.extend(copilot_auth_action_types);
filter
.hidden_action_types
.extend(copilot_no_auth_action_types);
}
Status::Authorized => {
filter
.hidden_action_types
.extend(copilot_no_auth_action_types);
for type_id in copilot_action_types
.iter()
.chain(&copilot_auth_action_types)
@ -80,7 +86,8 @@ pub fn init(
}
_ => {
filter.hidden_action_types.extend(copilot_action_types);
for type_id in &copilot_auth_action_types {
filter.hidden_action_types.extend(copilot_auth_action_types);
for type_id in &copilot_no_auth_action_types {
filter.hidden_action_types.remove(type_id);
}
}
@ -97,6 +104,7 @@ pub fn init(
}
});
cx.on_action(|_: &SignOut, cx| {
dbg!("Signing out");
if let Some(copilot) = Copilot::global(cx) {
copilot
.update(cx, |copilot, cx| copilot.sign_out(cx))