1use collections::{HashMap, HashSet};
2use extension::{
3 DownloadFileCapability, ExtensionCapability, NpmInstallPackageCapability, ProcessExecCapability,
4};
5use settings::{RegisterSetting, Settings};
6use std::sync::Arc;
7
8#[derive(Debug, Default, Clone, RegisterSetting)]
9pub struct ExtensionSettings {
10 /// The extensions that should be automatically installed by Zed.
11 ///
12 /// This is used to make functionality provided by extensions (e.g., language support)
13 /// available out-of-the-box.
14 ///
15 /// Default: { "html": true }
16 pub auto_install_extensions: HashMap<Arc<str>, bool>,
17 pub auto_update_extensions: HashMap<Arc<str>, bool>,
18 pub granted_capabilities: Vec<ExtensionCapability>,
19 /// The extension language model providers that are allowed to read API keys
20 /// from environment variables. Each entry is a provider ID in the format
21 /// "extension_id:provider_id".
22 pub allowed_env_var_providers: HashSet<Arc<str>>,
23 /// Tracks which legacy LLM providers have been migrated.
24 /// This prevents the migration from running multiple times and overriding user preferences.
25 pub migrated_llm_providers: HashSet<Arc<str>>,
26}
27
28impl ExtensionSettings {
29 /// Returns whether the given extension should be auto-installed.
30 pub fn should_auto_install(&self, extension_id: &str) -> bool {
31 self.auto_install_extensions
32 .get(extension_id)
33 .copied()
34 .unwrap_or(true)
35 }
36
37 pub fn should_auto_update(&self, extension_id: &str) -> bool {
38 self.auto_update_extensions
39 .get(extension_id)
40 .copied()
41 .unwrap_or(true)
42 }
43}
44
45impl Settings for ExtensionSettings {
46 fn from_settings(content: &settings::SettingsContent) -> Self {
47 Self {
48 auto_install_extensions: content.extension.auto_install_extensions.clone(),
49 auto_update_extensions: content.extension.auto_update_extensions.clone(),
50 granted_capabilities: content
51 .extension
52 .granted_extension_capabilities
53 .clone()
54 .unwrap_or_default()
55 .into_iter()
56 .map(|capability| match capability {
57 settings::ExtensionCapabilityContent::ProcessExec { command, args } => {
58 ExtensionCapability::ProcessExec(ProcessExecCapability { command, args })
59 }
60 settings::ExtensionCapabilityContent::DownloadFile { host, path } => {
61 ExtensionCapability::DownloadFile(DownloadFileCapability { host, path })
62 }
63 settings::ExtensionCapabilityContent::NpmInstallPackage { package } => {
64 ExtensionCapability::NpmInstallPackage(NpmInstallPackageCapability {
65 package,
66 })
67 }
68 })
69 .collect(),
70 allowed_env_var_providers: content
71 .extension
72 .allowed_env_var_providers
73 .clone()
74 .unwrap_or_default()
75 .into_iter()
76 .collect(),
77 migrated_llm_providers: content
78 .extension
79 .migrated_llm_providers
80 .clone()
81 .unwrap_or_default()
82 .into_iter()
83 .collect(),
84 }
85 }
86}