From 57a3d8c4914cad2c89b3c5ab2db9778e0beed1b2 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Tue, 28 Jan 2025 12:27:09 +0100 Subject: [PATCH] edit prediction: Hide rate completions modal behind feature flag (#23597) This hides the ability to rate completions behind the `predict-edits-rate-completions` feature flag Release Notes: - N/A --- Cargo.lock | 2 ++ crates/feature_flags/src/feature_flags.rs | 5 +++ .../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(-) diff --git a/Cargo.lock b/Cargo.lock index b1ba19ec31..4d1d6a843b 100644 --- a/Cargo.lock +++ b/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", diff --git a/crates/feature_flags/src/feature_flags.rs b/crates/feature_flags/src/feature_flags.rs index 4f2608cb6c..03699279e8 100644 --- a/crates/feature_flags/src/feature_flags.rs +++ b/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"; diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index 992d02733f..447b010c48 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/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 { 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::(), + |this| { + this.separator().entry( + "Rate Completions", + Some(RateCompletions.boxed_clone()), + move |window, cx| { + workspace + .update(cx, |workspace, cx| { + RateCompletionModal::toggle(workspace, window, cx) + }) + .ok(); + }, + ) + }, + ) }) } diff --git a/crates/zeta/Cargo.toml b/crates/zeta/Cargo.toml index 3656b7f725..a849c315bb 100644 --- a/crates/zeta/Cargo.toml +++ b/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 diff --git a/crates/zeta/src/rate_completion_modal.rs b/crates/zeta/src/rate_completion_modal.rs index 1e15b682d5..1617624456 100644 --- a/crates/zeta/src/rate_completion_modal.rs +++ b/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::() { + 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::()]; + + CommandPaletteFilter::update_global(cx, |filter, _cx| { + filter.hide_action_types(&rate_completion_action_types); + }); + + cx.observe_flag::(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 {