Encapsulate CommandPaletteFilter and CommandPaletteInterceptor (#9402)

This PR refactors the `CommandPaletteFilter` and
`CommandPaletteInterceptor` to better encapsulate their internals.

Previously these globals and their fields were publicly accessible,
which meant that there was a lot of reaching in and making
modifications.

These changes should make it easier to add additional consumers of these
hooks (right now they're primarily used by Vim mode).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-15 12:37:25 -04:00 committed by GitHub
parent d311a4b840
commit 55f4c8e51b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 164 additions and 56 deletions

View file

@ -66,33 +66,26 @@ pub fn init(
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::<CommandPaletteFilter>();
let filter = CommandPaletteFilter::global_mut(cx);
match status {
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);
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
.hidden_action_types
.extend(copilot_no_auth_action_types);
for type_id in copilot_action_types
.iter()
.chain(&copilot_auth_action_types)
{
filter.hidden_action_types.remove(type_id);
}
filter.hide_action_types(&copilot_no_auth_action_types);
filter.show_action_types(
copilot_action_types
.iter()
.chain(&copilot_auth_action_types),
);
}
_ => {
filter.hidden_action_types.extend(copilot_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);
}
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());
}
}
})