1use anyhow::Result;
2use collections::HashMap;
3use gpui::App;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use settings::{Settings, SettingsSources};
7use std::sync::Arc;
8
9#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
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 #[serde(default)]
16 pub auto_install_extensions: HashMap<Arc<str>, bool>,
17 #[serde(default)]
18 pub auto_update_extensions: HashMap<Arc<str>, bool>,
19}
20
21impl ExtensionSettings {
22 /// Returns whether the given extension should be auto-installed.
23 pub fn should_auto_install(&self, extension_id: &str) -> bool {
24 self.auto_install_extensions
25 .get(extension_id)
26 .copied()
27 .unwrap_or(true)
28 }
29
30 pub fn should_auto_update(&self, extension_id: &str) -> bool {
31 self.auto_update_extensions
32 .get(extension_id)
33 .copied()
34 .unwrap_or(true)
35 }
36}
37
38impl Settings for ExtensionSettings {
39 const KEY: Option<&'static str> = None;
40
41 type FileContent = Self;
42
43 fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> Result<Self> {
44 SettingsSources::<Self::FileContent>::json_merge_with(
45 [sources.default]
46 .into_iter()
47 .chain(sources.user)
48 .chain(sources.server),
49 )
50 }
51}