settings: Use a derive macro for refine (#38451)

When we refactored settings to not pass JSON blobs around, we ended up
needing
to write *a lot* of code that just merged things (like json merge used
to do).

Use a derive macro to prevent typos in this logic.

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2025-09-18 21:13:49 +00:00
committed by GitHub
parent 5f4f0a873e
commit b09764c54a
74 changed files with 1089 additions and 2818 deletions
+2 -14
View File
@@ -9,7 +9,7 @@ use http_client::{AsyncBody, HttpClient, HttpClientWithUrl};
use paths::remote_servers_dir;
use release_channel::{AppCommitSha, ReleaseChannel};
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsContent, SettingsStore};
use settings::{Settings, SettingsStore};
use smol::{fs, io::AsyncReadExt};
use smol::{fs::File, process::Command};
use std::{
@@ -119,21 +119,9 @@ struct AutoUpdateSetting(bool);
///
/// Default: true
impl Settings for AutoUpdateSetting {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
debug_assert_eq!(content.auto_update.unwrap(), true);
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
Self(content.auto_update.unwrap())
}
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
if let Some(auto_update) = content.auto_update {
self.0 = auto_update;
}
}
fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut SettingsContent) {
// We could match on vscode's update.mode here, but
// I think it's more important to have more people updating zed by default.
}
}
#[derive(Default)]