extension_settings.rs

 1use collections::HashMap;
 2use gpui::App;
 3use settings::Settings;
 4use std::sync::Arc;
 5
 6#[derive(Debug, Default, Clone)]
 7pub struct ExtensionSettings {
 8    /// The extensions that should be automatically installed by Zed.
 9    ///
10    /// This is used to make functionality provided by extensions (e.g., language support)
11    /// available out-of-the-box.
12    ///
13    /// Default: { "html": true }
14    pub auto_install_extensions: HashMap<Arc<str>, bool>,
15    pub auto_update_extensions: HashMap<Arc<str>, bool>,
16}
17
18impl ExtensionSettings {
19    /// Returns whether the given extension should be auto-installed.
20    pub fn should_auto_install(&self, extension_id: &str) -> bool {
21        self.auto_install_extensions
22            .get(extension_id)
23            .copied()
24            .unwrap_or(true)
25    }
26
27    pub fn should_auto_update(&self, extension_id: &str) -> bool {
28        self.auto_update_extensions
29            .get(extension_id)
30            .copied()
31            .unwrap_or(true)
32    }
33}
34
35impl Settings for ExtensionSettings {
36    fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
37        Self {
38            auto_install_extensions: content.extension.auto_install_extensions.clone(),
39            auto_update_extensions: content.extension.auto_update_extensions.clone(),
40        }
41    }
42
43    fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
44        self.auto_install_extensions
45            .extend(content.extension.auto_install_extensions.clone());
46        self.auto_update_extensions
47            .extend(content.extension.auto_update_extensions.clone());
48    }
49
50    fn import_from_vscode(
51        _vscode: &settings::VsCodeSettings,
52        _current: &mut settings::SettingsContent,
53    ) {
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}