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
+3 -19
View File
@@ -22,7 +22,7 @@ use rpc::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{SettingsContent, SettingsKey, SettingsStore, SettingsUi};
use settings::{SettingsContent, SettingsStore};
use util::{ResultExt as _, debug_panic};
use crate::ProjectEnvironment;
@@ -989,8 +989,7 @@ impl ExternalAgentServer for LocalCustomAgent {
pub const GEMINI_NAME: &'static str = "gemini";
pub const CLAUDE_CODE_NAME: &'static str = "claude";
#[derive(Default, Clone, JsonSchema, Debug, SettingsUi, SettingsKey, PartialEq)]
#[settings_key(key = "agent_servers")]
#[derive(Default, Clone, JsonSchema, Debug, PartialEq)]
pub struct AllAgentServersSettings {
pub gemini: Option<BuiltinAgentServerSettings>,
pub claude: Option<BuiltinAgentServerSettings>,
@@ -1063,7 +1062,7 @@ impl From<settings::CustomAgentServerSettings> for CustomAgentServerSettings {
}
impl settings::Settings for AllAgentServersSettings {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
let agent_settings = content.agent_servers.clone().unwrap();
Self {
gemini: agent_settings.gemini.map(Into::into),
@@ -1076,20 +1075,5 @@ impl settings::Settings for AllAgentServersSettings {
}
}
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
let Some(content) = &content.agent_servers else {
return;
};
if let Some(gemini) = content.gemini.clone() {
self.gemini = Some(gemini.into())
};
if let Some(claude) = content.claude.clone() {
self.claude = Some(claude.into());
}
for (name, config) in content.custom.clone() {
self.custom.insert(name, config.into());
}
}
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut SettingsContent) {}
}