ZIm/crates/extension_host/src/extension_settings.rs
Anthony 3c0ec5f612 Start work on creating the inital structure for the settings UI
We created a proc macro that derives the settings ui trait on types and
added that trait as a marker on Settings trait. Then we added the derive
macro on all settings

Co-authored-by: Ben Kunkle <ben@zed.dev>
2025-08-25 15:50:42 -04:00

59 lines
2 KiB
Rust

use anyhow::Result;
use collections::HashMap;
use gpui::App;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{DeriveSettingsUI as SettingsUI, Settings, SettingsSources};
use std::sync::Arc;
#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, SettingsUI)]
pub struct ExtensionSettings {
/// The extensions that should be automatically installed by Zed.
///
/// This is used to make functionality provided by extensions (e.g., language support)
/// available out-of-the-box.
///
/// Default: { "html": true }
#[serde(default)]
pub auto_install_extensions: HashMap<Arc<str>, bool>,
#[serde(default)]
pub auto_update_extensions: HashMap<Arc<str>, bool>,
}
impl ExtensionSettings {
/// Returns whether the given extension should be auto-installed.
pub fn should_auto_install(&self, extension_id: &str) -> bool {
self.auto_install_extensions
.get(extension_id)
.copied()
.unwrap_or(true)
}
pub fn should_auto_update(&self, extension_id: &str) -> bool {
self.auto_update_extensions
.get(extension_id)
.copied()
.unwrap_or(true)
}
}
impl Settings for ExtensionSettings {
const KEY: Option<&'static str> = None;
type FileContent = Self;
fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> Result<Self> {
SettingsSources::<Self::FileContent>::json_merge_with(
[sources.default]
.into_iter()
.chain(sources.user)
.chain(sources.server),
)
}
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
// settingsSync.ignoredExtensions controls autoupdate for vscode extensions, but we
// don't have a mapping to zed-extensions. there's also extensions.autoCheckUpdates
// and extensions.autoUpdate which are global switches, we don't support those yet
}
}