1use collections::HashMap;
2use extension::{
3 DownloadFileCapability, ExtensionCapability, NpmInstallPackageCapability, ProcessExecCapability,
4};
5use gpui::App;
6use settings::Settings;
7use std::sync::Arc;
8
9#[derive(Debug, Default, Clone)]
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 pub auto_install_extensions: HashMap<Arc<str>, bool>,
18 pub auto_update_extensions: HashMap<Arc<str>, bool>,
19 pub granted_capabilities: Vec<ExtensionCapability>,
20}
21
22impl ExtensionSettings {
23 /// Returns whether the given extension should be auto-installed.
24 pub fn should_auto_install(&self, extension_id: &str) -> bool {
25 self.auto_install_extensions
26 .get(extension_id)
27 .copied()
28 .unwrap_or(true)
29 }
30
31 pub fn should_auto_update(&self, extension_id: &str) -> bool {
32 self.auto_update_extensions
33 .get(extension_id)
34 .copied()
35 .unwrap_or(true)
36 }
37}
38
39impl Settings for ExtensionSettings {
40 fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
41 Self {
42 auto_install_extensions: content.extension.auto_install_extensions.clone(),
43 auto_update_extensions: content.extension.auto_update_extensions.clone(),
44 granted_capabilities: content
45 .extension
46 .granted_extension_capabilities
47 .clone()
48 .unwrap_or_default()
49 .into_iter()
50 .map(|capability| match capability {
51 settings::ExtensionCapabilityContent::ProcessExec { command, args } => {
52 ExtensionCapability::ProcessExec(ProcessExecCapability { command, args })
53 }
54 settings::ExtensionCapabilityContent::DownloadFile { host, path } => {
55 ExtensionCapability::DownloadFile(DownloadFileCapability { host, path })
56 }
57 settings::ExtensionCapabilityContent::NpmInstallPackage { package } => {
58 ExtensionCapability::NpmInstallPackage(NpmInstallPackageCapability {
59 package,
60 })
61 }
62 })
63 .collect(),
64 }
65 }
66}