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:
@@ -19,19 +19,10 @@ impl JupyterSettings {
|
||||
}
|
||||
|
||||
impl Settings for JupyterSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let jupyter = content.editor.jupyter.clone().unwrap();
|
||||
Self {
|
||||
kernel_selections: jupyter.kernel_selections.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(jupyter) = content.editor.jupyter.as_ref() else {
|
||||
return;
|
||||
};
|
||||
if let Some(kernel_selections) = jupyter.kernel_selections.clone() {
|
||||
self.kernel_selections.extend(kernel_selections)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use gpui::App;
|
||||
use settings::Settings;
|
||||
use util::MergeFrom;
|
||||
|
||||
/// Settings for configuring REPL display and behavior.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -18,7 +17,7 @@ pub struct ReplSettings {
|
||||
}
|
||||
|
||||
impl Settings for ReplSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let repl = content.repl.as_ref().unwrap();
|
||||
|
||||
Self {
|
||||
@@ -26,13 +25,4 @@ impl Settings for ReplSettings {
|
||||
max_columns: repl.max_columns.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(repl) = content.repl.as_ref() else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.max_columns.merge_from(&repl.max_columns);
|
||||
self.max_lines.merge_from(&repl.max_lines);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user