mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
extensions_ui: Add extension_suggestions setting to disable extension suggestions (#65109)
## Summary
Zed shows a notification suggesting extensions for the languages of the
files you open. Right now the only way to silence it is to dismiss each
suggestion one by one (stored per extension), or to add every extension
to `auto_install_extensions`. There is no way to turn the feature off as
a whole.
This adds an `extension_suggestions` setting (default `true`). When set
to `false`, `show_suggestion` returns early and no suggestion
notification is shown.
```json
{
"extension_suggestions": false
}
```
To make the feature discoverable, this also:
- Adds an **Extension Suggestions** toggle to the General settings page.
- Adds a third **Never Suggest Extensions** action to suggestion
notifications that disables the setting globally.
Changes: `ExtensionSettingsContent` / `ExtensionSettings` get the new
field (non-optional `bool` with `serde(default_true)`),
`assets/settings/default.json` and `docs/src/reference/all-settings.md`
document it, `settings_ui` renders the toggle on the General page,
`MessageNotification` gains support for a tertiary action, and
`extension_suggestions.rs` checks the setting and wires up the new
notification action.
## Testing
- Added `test_no_suggestion_when_extension_suggestions_disabled` (opens
`index.html` with the setting off, expects no notification).
- Added
`test_disabling_extension_suggestions_persists_and_stops_suggestions`
(invokes the new action, asserts the setting is disabled and no further
suggestions appear).
- `cargo test -p extensions_ui extension_suggestions`: 22 pass, 2 fail.
The 2 failures (`test_suggestion_returns_after_uninstall`,
`test_suggestion_returns_after_failed_install`) also fail on `main`
without this change.
- Manually checked on macOS with a local release build: the General →
Extensions toggle works, and the **Never Suggest Extensions** action
disables the setting globally.
To test: toggle it off in Settings → General → Extensions, or click
**Never Suggest Extensions** on a suggestion notification, then open a
file whose language has a suggested extension.
## Self-review
- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.
Release Notes:
- Added an `extension_suggestions` setting to turn off extension
suggestions.
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: MrSubidubi <finn@zed.dev>
Co-authored-by: Finn Evers <finn.evers@outlook.de>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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_capabilities
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}))
|
||||
|
||||
@@ -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) -> Self
|
||||
where
|
||||
S: 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(
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user