edit prediction: Hide rate completions modal behind feature flag (#23597)

Bennet Bo Fenner created

This hides the ability to rate completions behind the
`predict-edits-rate-completions` feature flag

Release Notes:

- N/A

Change summary

Cargo.lock                                                      |  2 
crates/feature_flags/src/feature_flags.rs                       |  5 
crates/inline_completion_button/src/inline_completion_button.rs | 33 +-
crates/zeta/Cargo.toml                                          |  2 
crates/zeta/src/rate_completion_modal.rs                        | 31 ++
5 files changed, 57 insertions(+), 16 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -16728,9 +16728,11 @@ dependencies = [
  "client",
  "clock",
  "collections",
+ "command_palette_hooks",
  "ctor",
  "editor",
  "env_logger 0.11.6",
+ "feature_flags",
  "futures 0.3.31",
  "gpui",
  "http_client",

crates/feature_flags/src/feature_flags.rs 🔗

@@ -56,6 +56,11 @@ impl FeatureFlag for PredictEditsFeatureFlag {
     const NAME: &'static str = "predict-edits";
 }
 
+pub struct PredictEditsRateCompletionsFeatureFlag;
+impl FeatureFlag for PredictEditsRateCompletionsFeatureFlag {
+    const NAME: &'static str = "predict-edits-rate-completions";
+}
+
 pub struct GitUiFeatureFlag;
 impl FeatureFlag for GitUiFeatureFlag {
     const NAME: &'static str = "git-ui";

crates/inline_completion_button/src/inline_completion_button.rs 🔗

@@ -2,7 +2,9 @@ use anyhow::Result;
 use client::UserStore;
 use copilot::{Copilot, Status};
 use editor::{scroll::Autoscroll, Editor};
-use feature_flags::{FeatureFlagAppExt, PredictEditsFeatureFlag};
+use feature_flags::{
+    FeatureFlagAppExt, PredictEditsFeatureFlag, PredictEditsRateCompletionsFeatureFlag,
+};
 use fs::Fs;
 use gpui::{
     actions, div, pulsating_between, Action, Animation, AnimationExt, App, AsyncWindowContext,
@@ -463,19 +465,22 @@ impl InlineCompletionButton {
     ) -> Entity<ContextMenu> {
         let workspace = self.workspace.clone();
         ContextMenu::build(window, cx, |menu, _window, cx| {
-            self.build_language_settings_menu(menu, cx)
-                .separator()
-                .entry(
-                    "Rate Completions",
-                    Some(RateCompletions.boxed_clone()),
-                    move |window, cx| {
-                        workspace
-                            .update(cx, |workspace, cx| {
-                                RateCompletionModal::toggle(workspace, window, cx)
-                            })
-                            .ok();
-                    },
-                )
+            self.build_language_settings_menu(menu, cx).when(
+                cx.has_flag::<PredictEditsRateCompletionsFeatureFlag>(),
+                |this| {
+                    this.separator().entry(
+                        "Rate Completions",
+                        Some(RateCompletions.boxed_clone()),
+                        move |window, cx| {
+                            workspace
+                                .update(cx, |workspace, cx| {
+                                    RateCompletionModal::toggle(workspace, window, cx)
+                                })
+                                .ok();
+                        },
+                    )
+                },
+            )
         })
     }
 

crates/zeta/Cargo.toml 🔗

@@ -21,7 +21,9 @@ anyhow.workspace = true
 arrayvec.workspace = true
 client.workspace = true
 collections.workspace = true
+command_palette_hooks.workspace = true
 editor.workspace = true
+feature_flags.workspace = true
 futures.workspace = true
 gpui.workspace = true
 http_client.workspace = true

crates/zeta/src/rate_completion_modal.rs 🔗

@@ -1,8 +1,10 @@
 use crate::{CompletionDiffElement, InlineCompletion, InlineCompletionRating, Zeta};
+use command_palette_hooks::CommandPaletteFilter;
 use editor::Editor;
+use feature_flags::{FeatureFlagAppExt as _, PredictEditsRateCompletionsFeatureFlag};
 use gpui::{actions, prelude::*, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable};
 use language::language_settings;
-use std::time::Duration;
+use std::{any::TypeId, time::Duration};
 use ui::{prelude::*, KeyBinding, List, ListItem, ListItemSpacing, Tooltip};
 use workspace::{ModalView, Workspace};
 
@@ -22,10 +24,35 @@ actions!(
 pub fn init(cx: &mut App) {
     cx.observe_new(move |workspace: &mut Workspace, _, _cx| {
         workspace.register_action(|workspace, _: &RateCompletions, window, cx| {
-            RateCompletionModal::toggle(workspace, window, cx);
+            if cx.has_flag::<PredictEditsRateCompletionsFeatureFlag>() {
+                RateCompletionModal::toggle(workspace, window, cx);
+            }
         });
     })
     .detach();
+
+    feature_gate_predict_edits_rating_actions(cx);
+}
+
+fn feature_gate_predict_edits_rating_actions(cx: &mut App) {
+    let rate_completion_action_types = [TypeId::of::<RateCompletions>()];
+
+    CommandPaletteFilter::update_global(cx, |filter, _cx| {
+        filter.hide_action_types(&rate_completion_action_types);
+    });
+
+    cx.observe_flag::<PredictEditsRateCompletionsFeatureFlag, _>(move |is_enabled, cx| {
+        if is_enabled {
+            CommandPaletteFilter::update_global(cx, |filter, _cx| {
+                filter.show_action_types(rate_completion_action_types.iter());
+            });
+        } else {
+            CommandPaletteFilter::update_global(cx, |filter, _cx| {
+                filter.hide_action_types(&rate_completion_action_types);
+            });
+        }
+    })
+    .detach();
 }
 
 pub struct RateCompletionModal {