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:
@@ -30,7 +30,7 @@ use std::{
|
||||
};
|
||||
use theme::Theme;
|
||||
use ui::{Color, Icon, IntoElement, Label, LabelCommon};
|
||||
use util::{MergeFrom as _, ResultExt};
|
||||
use util::ResultExt;
|
||||
|
||||
pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
|
||||
|
||||
@@ -65,7 +65,7 @@ pub struct PreviewTabsSettings {
|
||||
}
|
||||
|
||||
impl Settings for ItemSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let tabs = content.tabs.as_ref().unwrap();
|
||||
Self {
|
||||
git_status: tabs.git_status.unwrap(),
|
||||
@@ -77,18 +77,6 @@ impl Settings for ItemSettings {
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(tabs) = content.tabs.as_ref() else {
|
||||
return;
|
||||
};
|
||||
self.git_status.merge_from(&tabs.git_status);
|
||||
self.close_position.merge_from(&tabs.close_position);
|
||||
self.activate_on_close.merge_from(&tabs.activate_on_close);
|
||||
self.file_icons.merge_from(&tabs.file_icons);
|
||||
self.show_diagnostics.merge_from(&tabs.show_diagnostics);
|
||||
self.show_close_button.merge_from(&tabs.show_close_button);
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
@@ -125,7 +113,7 @@ impl Settings for ItemSettings {
|
||||
}
|
||||
|
||||
impl Settings for PreviewTabsSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let preview_tabs = content.preview_tabs.as_ref().unwrap();
|
||||
Self {
|
||||
enabled: preview_tabs.enabled.unwrap(),
|
||||
@@ -136,18 +124,6 @@ impl Settings for PreviewTabsSettings {
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(preview_tabs) = content.preview_tabs.as_ref() else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.enabled.merge_from(&preview_tabs.enabled);
|
||||
self.enable_preview_from_file_finder
|
||||
.merge_from(&preview_tabs.enable_preview_from_file_finder);
|
||||
self.enable_preview_from_code_navigation
|
||||
.merge_from(&preview_tabs.enable_preview_from_code_navigation);
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
|
||||
Reference in New Issue
Block a user