diff --git a/assets/settings/default.json b/assets/settings/default.json index 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.rs index 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, bool>, pub auto_update_extensions: HashMap, bool>, + pub suggest_extensions: bool, pub granted_capabilities: Vec, } @@ -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_capabilities diff --git a/crates/extensions_ui/src/extension_suggestions.rs b/crates/extensions_ui/src/extension_suggestions.rs index 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::(|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::() + .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.rs index 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, bool>, #[serde(default)] pub auto_update_extensions: HashMap, 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>, } +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.rs index 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.rs index 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