1use anyhow::Result;
2use collections::HashMap;
3use gpui::App;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use settings::{Settings, SettingsSources, SettingsUi};
7use std::sync::Arc;
8
9#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, SettingsUi)]
10pub struct ExtensionSettings {
11 /// The extensions that should be automatically installed by Zed.
12 ///
13 /// This is used to make functionality provided by extensions (e.g., language support)
14 /// available out-of-the-box.
15 ///
16 /// Default: { "html": true }
17 #[serde(default)]
18 pub auto_install_extensions: HashMap<Arc<str>, bool>,
19 #[serde(default)]
20 pub auto_update_extensions: HashMap<Arc<str>, bool>,
21}
22
23impl ExtensionSettings {
24 /// Returns whether the given extension should be auto-installed.
25 pub fn should_auto_install(&self, extension_id: &str) -> bool {
26 self.auto_install_extensions
27 .get(extension_id)
28 .copied()
29 .unwrap_or(true)
30 }
31
32 pub fn should_auto_update(&self, extension_id: &str) -> bool {
33 self.auto_update_extensions
34 .get(extension_id)
35 .copied()
36 .unwrap_or(true)
37 }
38}
39
40impl Settings for ExtensionSettings {
41 const KEY: Option<&'static str> = None;
42
43 type FileContent = Self;
44
45 fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> Result<Self> {
46 SettingsSources::<Self::FileContent>::json_merge_with(
47 [sources.default]
48 .into_iter()
49 .chain(sources.user)
50 .chain(sources.server),
51 )
52 }
53
54 fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
55 // settingsSync.ignoredExtensions controls autoupdate for vscode extensions, but we
56 // don't have a mapping to zed-extensions. there's also extensions.autoCheckUpdates
57 // and extensions.autoUpdate which are global switches, we don't support those yet
58 }
59}