init.rs

 1use std::any::{Any, TypeId};
 2
 3use command_palette_hooks::CommandPaletteFilter;
 4use feature_flags::{
 5    FeatureFlagAppExt as _, PredictEditsFeatureFlag, PredictEditsRateCompletionsFeatureFlag,
 6};
 7use ui::App;
 8use workspace::Workspace;
 9
10use crate::{onboarding_modal::ZedPredictModal, RateCompletionModal, RateCompletions};
11
12pub fn init(cx: &mut App) {
13    cx.observe_new(move |workspace: &mut Workspace, _, _cx| {
14        workspace.register_action(|workspace, _: &RateCompletions, window, cx| {
15            if cx.has_flag::<PredictEditsRateCompletionsFeatureFlag>() {
16                RateCompletionModal::toggle(workspace, window, cx);
17            }
18        });
19
20        workspace.register_action(
21            move |workspace, _: &zed_actions::OpenZedPredictOnboarding, window, cx| {
22                if cx.has_flag::<PredictEditsFeatureFlag>() {
23                    ZedPredictModal::toggle(
24                        workspace,
25                        workspace.user_store().clone(),
26                        workspace.client().clone(),
27                        workspace.app_state().fs.clone(),
28                        window,
29                        cx,
30                    )
31                }
32            },
33        );
34    })
35    .detach();
36
37    feature_gate_predict_edits_rating_actions(cx);
38}
39
40fn feature_gate_predict_edits_rating_actions(cx: &mut App) {
41    let rate_completion_action_types = [TypeId::of::<RateCompletions>()];
42
43    CommandPaletteFilter::update_global(cx, |filter, _cx| {
44        filter.hide_action_types(&rate_completion_action_types);
45        filter.hide_action_types(&[zed_actions::OpenZedPredictOnboarding.type_id()]);
46    });
47
48    cx.observe_flag::<PredictEditsRateCompletionsFeatureFlag, _>(move |is_enabled, cx| {
49        if is_enabled {
50            CommandPaletteFilter::update_global(cx, |filter, _cx| {
51                filter.show_action_types(rate_completion_action_types.iter());
52            });
53        } else {
54            CommandPaletteFilter::update_global(cx, |filter, _cx| {
55                filter.hide_action_types(&rate_completion_action_types);
56            });
57        }
58    })
59    .detach();
60}