Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
extensions_ui: Add `extension_suggestions` setting to disable extension suggestions (#65109)
Audi Nugrahae7c8cbeed602
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex fe87add3b99..0a926bdd0df 100644--- a/assets/settings/default.json+++ b/assets/settings/default.json@@ -2339,6 +2339,8 @@"auto_install_extensions": {"html": true,},+ // Whether to suggest installing extensions based on the files you open.+ "suggest_extensions": true,// The capabilities granted to extensions.//// This list can be customized to restrict what extensions are able to do.diff --git a/crates/extension_host/src/extension_settings.rs b/crates/extension_host/src/extension_settings.rsindex 736dd6b87ae..2cb35df94f8 100644--- a/crates/extension_host/src/extension_settings.rs+++ b/crates/extension_host/src/extension_settings.rs@@ -15,6 +15,7 @@ pub struct ExtensionSettings {/// Default: { "html": true }pub auto_install_extensions: HashMap<Arc<str>, bool>,pub auto_update_extensions: HashMap<Arc<str>, bool>,+ pub suggest_extensions: bool,pub granted_capabilities: Vec<ExtensionCapability>,}@@ -40,6 +41,7 @@ impl Settings for ExtensionSettings {Self {auto_install_extensions: content.extension.auto_install_extensions.clone(),auto_update_extensions: content.extension.auto_update_extensions.clone(),+ suggest_extensions: content.extension.suggest_extensions,granted_capabilities: content.extension.granted_extension_capabilitiesdiff --git a/crates/extensions_ui/src/extension_suggestions.rs b/crates/extensions_ui/src/extension_suggestions.rsindex 9080c5297d2..0d6103e431e 100644--- a/crates/extensions_ui/src/extension_suggestions.rs+++ b/crates/extensions_ui/src/extension_suggestions.rs@@ -196,6 +196,9 @@ fn show_suggestion(if workspace.has_notification(¬ification_id) {return;}+ if !ExtensionSettings::get_global(cx).suggest_extensions {+ return;+ }let extension_store = ExtensionStore::global(cx);let extension_store = extension_store.read(cx);@@ -231,10 +234,20 @@ fn show_suggestion(.secondary_icon(IconName::Close).secondary_icon_color(Color::Error).secondary_on_click(move |_window, cx| dismiss_suggestion(&extension_id, cx))+ .secondary_menu_entry("Disable Suggestions", |_window, cx| {+ disable_extension_suggestions(cx)+ })})});}+fn disable_extension_suggestions(cx: &mut App) {+ let fs = AppState::global(cx).fs.clone();+ settings::update_settings_file(fs, cx, |content, _| {+ content.extension.suggest_extensions = false;+ });+}+#[cfg(test)]mod tests {use super::*;@@ -327,6 +340,54 @@ mod tests {assert_eq!(notification_ids(&workspace, cx), Vec::new());}+ #[gpui::test]+ async fn test_no_suggestion_when_suggest_extensions_disabled(cx: &mut TestAppContext) {+ let app_state = init_test(cx);+ cx.update(|cx| {+ cx.update_global::<SettingsStore, _>(|store, cx| {+ store.update_user_settings(cx, |content| {+ content.extension.suggest_extensions = false;+ });+ });+ });+ let (workspace, cx) = open_test_workspace(&app_state, cx).await;++ open_file(&workspace, "index.html", cx).await;+ open_file(&workspace, "main.gleam", cx).await;++ assert_eq!(notification_ids(&workspace, cx), Vec::new());+ }++ #[gpui::test]+ async fn test_disabling_extension_suggestions_stops_suggestions(cx: &mut TestAppContext) {+ let app_state = init_test(cx);+ let (workspace, cx) = open_test_workspace(&app_state, cx).await;+ open_file(&workspace, "index.html", cx).await;+ assert_eq!(+ notification_ids(&workspace, cx),+ vec![notification_id(EMMET_EXTENSION_ID)]+ );++ let notification = notification_views(&workspace, cx)+ .pop()+ .unwrap()+ .downcast::<MessageNotification>()+ .ok()+ .unwrap();+ cx.update(|_, cx| disable_extension_suggestions(cx));+ notification.update(cx, |notification, cx| notification.dismiss(cx));+ cx.run_until_parked();++ assert_eq!(notification_ids(&workspace, cx), Vec::new());+ cx.update(|_, cx| {+ assert!(!ExtensionSettings::get_global(cx).suggest_extensions);+ assert!(!suggestion_dismissed(EMMET_EXTENSION_ID, cx));+ });++ open_file(&workspace, "other.html", cx).await;+ assert_eq!(notification_ids(&workspace, cx), Vec::new());+ }+#[gpui::test]async fn test_no_suggestion_after_dismissal(cx: &mut TestAppContext) {let app_state = init_test(cx);diff --git a/crates/settings_content/src/extension.rs b/crates/settings_content/src/extension.rsindex 2fefd4ef38a..701c4b84d66 100644--- a/crates/settings_content/src/extension.rs+++ b/crates/settings_content/src/extension.rs@@ -4,9 +4,10 @@ use collections::HashMap;use schemars::JsonSchema;use serde::{Deserialize, Serialize};use settings_macros::{MergeFrom, with_fallible_options};+use util::serde::default_true;#[with_fallible_options]-#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]+#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct ExtensionSettingsContent {/// The extensions that should be automatically installed by Zed.///@@ -18,10 +19,26 @@ pub struct ExtensionSettingsContent {pub auto_install_extensions: HashMap<Arc<str>, bool>,#[serde(default)]pub auto_update_extensions: HashMap<Arc<str>, bool>,+ /// Whether to suggest installing extensions based on the files you open.+ ///+ /// Default: true+ #[serde(default = "default_true")]+ pub suggest_extensions: bool,/// The capabilities granted to extensions.pub granted_extension_capabilities: Option<Vec<ExtensionCapabilityContent>>,}+impl Default for ExtensionSettingsContent {+ fn default() -> Self {+ Self {+ auto_install_extensions: HashMap::default(),+ auto_update_extensions: HashMap::default(),+ suggest_extensions: true,+ granted_extension_capabilities: None,+ }+ }+}+/// A capability for an extension.#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, JsonSchema)]#[serde(tag = "kind", rename_all = "snake_case")]diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rsindex 525511fbf4f..9da1f4fc4f4 100644--- a/crates/settings_ui/src/page_data.rs+++ b/crates/settings_ui/src/page_data.rs@@ -517,6 +517,26 @@ fn general_page(cx: &App) -> SettingsPage {]}+ fn extensions_section() -> [SettingsPageItem; 2] {+ [+ SettingsPageItem::SectionHeader("Extensions"),+ SettingsPageItem::SettingItem(SettingItem {+ title: "Suggest Extensions",+ description: "Whether to suggest installing extensions based on the files you open.",+ field: Box::new(SettingField {+ organization_override: None,+ json_path: Some("suggest_extensions"),+ pick: |settings_content| Some(&settings_content.extension.suggest_extensions),+ write: |settings_content, value, _| {+ settings_content.extension.suggest_extensions = value.unwrap_or(true);+ },+ }),+ metadata: None,+ files: USER,+ }),+ ]+ }+SettingsPage {title: "General",items: concat_sections!(@@ -527,6 +547,7 @@ fn general_page(cx: &App) -> SettingsPage {scoped_settings_section(),privacy_section(),auto_update_section(),+ extensions_section(),).into(),}diff --git a/crates/ui/src/components/button/split_button.rs b/crates/ui/src/components/button/split_button.rsindex 0173474690d..2b870cea149 100644--- a/crates/ui/src/components/button/split_button.rs+++ b/crates/ui/src/components/button/split_button.rs@@ -17,10 +17,17 @@ pub enum SplitButtonStyle {}pub enum SplitButtonKind {+ Button(Button),ButtonLike(ButtonLike),IconButton(IconButton),}+impl From<Button> for SplitButtonKind {+ fn from(button: Button) -> Self {+ Self::Button(button)+ }+}+impl From<IconButton> for SplitButtonKind {fn from(icon_button: IconButton) -> Self {Self::IconButton(icon_button)@@ -78,6 +85,7 @@ impl RenderOnce for SplitButton {this.gap_px()}).child(div().flex_grow_1().child(match self.left {+ SplitButtonKind::Button(button) => button.into_any_element(),SplitButtonKind::ButtonLike(button) => button.into_any_element(),SplitButtonKind::IconButton(icon) => icon.into_any_element(),}))diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rsindex 697f4f3ed51..9a07a77e8a9 100644--- a/crates/workspace/src/notifications.rs+++ b/crates/workspace/src/notifications.rs@@ -486,7 +486,11 @@ pub mod simple_message_notification {AnyElement, DismissEvent, EventEmitter, FocusHandle, Focusable, ParentElement, Render,ScrollHandle, SharedString, Styled, Task,};- use ui::{CopyButton, Tooltip, WithScrollbar, prelude::*};+ use ui::{+ ContextMenu, CopyButton, PopoverMenu, SplitButton, SplitButtonStyle, Tooltip,+ WithScrollbar, prelude::*,+ };+ use util::ResultExt as _;use crate::SuppressNotification;use crate::workspace_error::{@@ -667,6 +671,7 @@ pub mod simple_message_notification {secondary_icon: Option<ActionIcon>,secondary_icon_color: Option<Color>,secondary_on_click: Option<Arc<dyn Fn(&mut Window, &mut Context<Self>)>>,+ secondary_menu_entries: Vec<(SharedString, Arc<dyn Fn(&mut Window, &mut Context<Self>)>)>,more_info_message: Option<SharedString>,more_info_url: Option<Arc<str>>,show_close_button: bool,@@ -719,6 +724,7 @@ pub mod simple_message_notification {secondary_icon: None,secondary_icon_color: None,secondary_on_click: None,+ secondary_menu_entries: Vec::new(),more_info_message: None,more_info_url: None,show_close_button: true,@@ -817,6 +823,52 @@ pub mod simple_message_notification {self}+ /// Adds an entry to a dropdown attached to the secondary action button,+ /// turning it into a split button. Like the buttons themselves, choosing+ /// an entry dismisses the notification.+ pub fn secondary_menu_entry<S, F>(mut self, label: S, on_click: F) -> Self+ where+ S: Into<SharedString>,+ F: 'static + Fn(&mut Window, &mut Context<Self>),+ {+ self.secondary_menu_entries+ .push((label.into(), Arc::new(on_click)));+ self+ }++ fn render_secondary_menu(&self, cx: &mut Context<Self>) -> AnyElement {+ let notification = cx.weak_entity();+ let entries = self.secondary_menu_entries.clone();+ PopoverMenu::new(("notification-secondary-menu", cx.entity_id()))+ .trigger_with_tooltip(+ IconButton::new(+ ("notification-secondary-menu-trigger", cx.entity_id()),+ IconName::ChevronDown,+ )+ .icon_size(IconSize::XSmall)+ .icon_color(Color::Muted),+ Tooltip::text("More Options"),+ )+ .menu(move |window, cx| {+ let entries = entries.clone();+ let notification = notification.clone();+ Some(ContextMenu::build(window, cx, move |menu, _, _| {+ entries.into_iter().fold(menu, |menu, (label, on_click)| {+ let notification = notification.clone();+ menu.entry(label, None, move |window, cx| {+ notification+ .update(cx, |this, cx| {+ on_click(window, cx);+ this.dismiss(cx);+ })+ .log_err();+ })+ })+ }))+ })+ .into_any_element()+ }+pub fn more_info_message<S>(mut self, message: S) -> SelfwhereS: Into<SharedString>,@@ -1061,8 +1113,8 @@ pub mod simple_message_notification {}})}))- .children(self.secondary_message.iter().map(|message| {- Button::new(("notification-secondary", cx.entity_id()), message.clone())+ .children(self.secondary_message.clone().map(|message| {+ let button = Button::new(("notification-secondary", cx.entity_id()), message).when_some(self.button_style, |button, style| button.style(style)).label_size(LabelSize::Small).on_click(cx.listener(|this, _, window, cx| {@@ -1079,7 +1131,14 @@ pub mod simple_message_notification {IconPosition::Start => button.start_icon(element),IconPosition::End => button.end_icon(element),}- })+ });+ if self.secondary_menu_entries.is_empty() {+ button.into_any_element()+ } else {+ SplitButton::new(button, self.render_secondary_menu(cx))+ .style(SplitButtonStyle::Transparent)+ .into_any_element()+ }})).child(h_flex().w_full().justify_end().children(diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.mdindex 46e9643e76e..4d95a7479af 100644--- a/docs/src/reference/all-settings.md+++ b/docs/src/reference/all-settings.md@@ -319,6 +319,22 @@ Define extensions which should be installed (`true`) or never installed (`false`}```+## Suggest Extensions++- Description: Whether to suggest installing extensions based on the files you open.+- Setting: `suggest_extensions`+- Default: `true`++**Options**++`boolean` values++```json [settings]+{+ "suggest_extensions": false+}+```+## Auto Update extensions- Description: Disable auto-updates for specific extensions.