diff --git a/Cargo.lock b/Cargo.lock index 819a3383c6969b378ba6f2e51e8cdd98ceba1ae6..4296d262e38e0d3134605927b7e39162c3c78e6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,6 +345,7 @@ dependencies = [ "ctor", "editor", "env_logger", + "feature_flags", "file_icons", "fs", "futures 0.3.28", @@ -13001,7 +13002,7 @@ dependencies = [ [[package]] name = "zed" -version = "0.137.3" +version = "0.137.4" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/assistant/Cargo.toml b/crates/assistant/Cargo.toml index 4a3b131a528154817445598326c407336608421e..184232437eed03a52430c51710661b4e76b0686d 100644 --- a/crates/assistant/Cargo.toml +++ b/crates/assistant/Cargo.toml @@ -18,6 +18,7 @@ client.workspace = true collections.workspace = true command_palette_hooks.workspace = true editor.workspace = true +feature_flags.workspace = true file_icons.workspace = true fs.workspace = true futures.workspace = true diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 603c5aa4398b21ad405926fd515564d0b87898e5..2763a3bfe8fff6781706a58c9526d822d72e1a9e 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -22,6 +22,7 @@ use editor::{ Anchor, Editor, EditorElement, EditorEvent, EditorStyle, MultiBufferSnapshot, RowExt, ToOffset as _, ToPoint, }; +use feature_flags::{FeatureFlag, FeatureFlagAppExt, FeatureFlagViewExt}; use file_icons::FileIcons; use fs::Fs; use futures::StreamExt; @@ -117,6 +118,12 @@ struct ActiveConversationEditor { _subscriptions: Vec, } +struct PromptLibraryFeatureFlag; + +impl FeatureFlag for PromptLibraryFeatureFlag { + const NAME: &'static str = "prompt-library"; +} + impl AssistantPanel { const INLINE_PROMPT_HISTORY_MAX_LEN: usize = 20; @@ -142,6 +149,9 @@ impl AssistantPanel { let workspace_handle = workspace.clone(); workspace.update(&mut cx, |workspace, cx| { cx.new_view::(|cx| { + cx.observe_flag::(|_, _, cx| cx.notify()) + .detach(); + const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100); let _watch_saved_conversations = cx.spawn(move |this, mut cx| async move { let mut events = fs @@ -1129,48 +1139,49 @@ impl AssistantPanel { } fn render_signed_in(&mut self, cx: &mut ViewContext) -> impl IntoElement { - let header = - TabBar::new("assistant_header") - .start_child(h_flex().gap_1().child(self.render_popover_button(cx))) - .children(self.active_conversation_editor().map(|editor| { - h_flex() - .h(rems(Tab::CONTAINER_HEIGHT_IN_REMS)) - .flex_1() - .px_2() - .child(Label::new(editor.read(cx).title(cx)).into_element()) - })) - .end_child( - h_flex() - .gap_2() - .when_some(self.active_conversation_editor(), |this, editor| { - let conversation = editor.read(cx).conversation.clone(); - this.child( - h_flex() - .gap_1() - .child(self.render_model(&conversation, cx)) - .children(self.render_remaining_tokens(&conversation, cx)), - ) - .child( - ui::Divider::vertical() - .inset() - .color(ui::DividerColor::Border), - ) - }) - .child( + let header = TabBar::new("assistant_header") + .start_child(h_flex().gap_1().child(self.render_popover_button(cx))) + .children(self.active_conversation_editor().map(|editor| { + h_flex() + .h(rems(Tab::CONTAINER_HEIGHT_IN_REMS)) + .flex_1() + .px_2() + .child(Label::new(editor.read(cx).title(cx)).into_element()) + })) + .end_child( + h_flex() + .gap_2() + .when_some(self.active_conversation_editor(), |this, editor| { + let conversation = editor.read(cx).conversation.clone(); + this.child( h_flex() .gap_1() - .child(self.render_inject_context_menu(cx)) - .child( + .child(self.render_model(&conversation, cx)) + .children(self.render_remaining_tokens(&conversation, cx)), + ) + .child( + ui::Divider::vertical() + .inset() + .color(ui::DividerColor::Border), + ) + }) + .child( + h_flex() + .gap_1() + .child(self.render_inject_context_menu(cx)) + .children( + cx.has_flag::().then_some( IconButton::new("show_prompt_manager", IconName::Library) .icon_size(IconSize::Small) .on_click(cx.listener(|this, _event, cx| { this.show_prompt_manager(cx) })) .tooltip(|cx| Tooltip::text("Prompt Library…", cx)), - ) - .child(Self::render_assist_button(cx)), - ), - ); + ), + ) + .child(Self::render_assist_button(cx)), + ), + ); let contents = if self.active_conversation_editor().is_some() { let mut registrar = DivRegistrar::new( diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index f97f45abe98bdaadea778f3802f4809a77c4fd38..5f9889e3e578376b3c3f30a635662ffc80f822e3 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -192,10 +192,13 @@ impl UserStore { cx.update(|cx| { if let Some(info) = info { - cx.update_flags(info.staff, info.flags); + let disable_staff = std::env::var("ZED_DISABLE_STAFF") + .map_or(false, |v| v != "" && v != "0"); + let staff = info.staff && !disable_staff; + cx.update_flags(staff, info.flags); client.telemetry.set_authenticated_user_info( Some(info.metrics_id.clone()), - info.staff, + staff, ) } })?; diff --git a/crates/feature_flags/src/feature_flags.rs b/crates/feature_flags/src/feature_flags.rs index 0823e2f460c7c1326b9f301cc668cd78565d6ee8..200468d6f32e158542d02cde116f7330c5b3f32b 100644 --- a/crates/feature_flags/src/feature_flags.rs +++ b/crates/feature_flags/src/feature_flags.rs @@ -14,6 +14,12 @@ impl FeatureFlags { impl Global for FeatureFlags {} +/// To create a feature flag, implement this trait on a trivial type and use it as +/// a generic parameter when called [`FeatureFlagAppExt::has_flag`]. +/// +/// Feature flags are always enabled for members of Zed staff. To disable this behavior +/// so you can test flags being disabled, set ZED_DISABLE_STAFF=1 in your environment, +/// which will force Zed to treat the current user as non-staff. pub trait FeatureFlag { const NAME: &'static str; } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index f2c04d591f95b5595236ebe3861069b75b3ac151..b5f0ad6c5e95e81a54a17032699a1c68f6526b11 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -2,7 +2,7 @@ description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.137.3" +version = "0.137.4" publish = false license = "GPL-3.0-or-later" authors = ["Zed Team "]