extension_settings.rs

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