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 -33
View File
@@ -1,7 +1,6 @@
use gpui::Pixels;
use settings::Settings;
use ui::px;
use util::MergeFrom as _;
use workspace::dock::DockPosition;
#[derive(Debug)]
@@ -19,7 +18,7 @@ pub struct NotificationPanelSettings {
}
impl Settings for CollaborationPanelSettings {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
fn from_settings(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
let panel = content.collaboration_panel.as_ref().unwrap();
Self {
@@ -28,25 +27,10 @@ impl Settings for CollaborationPanelSettings {
default_width: panel.default_width.map(px).unwrap(),
}
}
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut ui::App) {
if let Some(panel) = content.collaboration_panel.as_ref() {
self.button.merge_from(&panel.button);
self.default_width
.merge_from(&panel.default_width.map(Pixels::from));
self.dock.merge_from(&panel.dock.map(Into::into));
}
}
fn import_from_vscode(
_vscode: &settings::VsCodeSettings,
_content: &mut settings::SettingsContent,
) {
}
}
impl Settings for NotificationPanelSettings {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
fn from_settings(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
let panel = content.notification_panel.as_ref().unwrap();
return Self {
button: panel.button.unwrap(),
@@ -54,19 +38,4 @@ impl Settings for NotificationPanelSettings {
default_width: panel.default_width.map(px).unwrap(),
};
}
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut ui::App) {
let Some(panel) = content.notification_panel.as_ref() else {
return;
};
self.button.merge_from(&panel.button);
self.dock.merge_from(&panel.dock.map(Into::into));
self.default_width.merge_from(&panel.default_width.map(px));
}
fn import_from_vscode(
_vscode: &settings::VsCodeSettings,
_current: &mut settings::SettingsContent,
) {
}
}