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
@@ -19,29 +19,28 @@ use remote::{
SshConnectionOptions,
};
pub use settings::SshConnection;
use settings::{Settings, WslConnection};
use settings::{ExtendingVec, Settings, WslConnection};
use theme::ThemeSettings;
use ui::{
ActiveTheme, Color, CommonAnimationExt, Context, Icon, IconName, IconSize, InteractiveElement,
IntoElement, Label, LabelCommon, Styled, Window, prelude::*,
};
use util::MergeFrom;
use workspace::{AppState, ModalView, Workspace};
pub struct SshSettings {
pub ssh_connections: Vec<SshConnection>,
pub wsl_connections: Vec<WslConnection>,
pub ssh_connections: ExtendingVec<SshConnection>,
pub wsl_connections: ExtendingVec<WslConnection>,
/// Whether to read ~/.ssh/config for ssh connection sources.
pub read_ssh_config: bool,
}
impl SshSettings {
pub fn ssh_connections(&self) -> impl Iterator<Item = SshConnection> + use<> {
self.ssh_connections.clone().into_iter()
self.ssh_connections.clone().0.into_iter()
}
pub fn wsl_connections(&self) -> impl Iterator<Item = WslConnection> + use<> {
self.wsl_connections.clone().into_iter()
self.wsl_connections.clone().0.into_iter()
}
pub fn fill_connection_options_from_settings(&self, options: &mut SshConnectionOptions) {
@@ -104,25 +103,14 @@ impl From<WslConnection> for Connection {
}
impl Settings for SshSettings {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
let remote = &content.remote;
Self {
ssh_connections: remote.ssh_connections.clone().unwrap_or_default(),
wsl_connections: remote.wsl_connections.clone().unwrap_or_default(),
ssh_connections: remote.ssh_connections.clone().unwrap_or_default().into(),
wsl_connections: remote.wsl_connections.clone().unwrap_or_default().into(),
read_ssh_config: remote.read_ssh_config.unwrap(),
}
}
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
if let Some(ssh_connections) = content.remote.ssh_connections.clone() {
self.ssh_connections.extend(ssh_connections)
}
if let Some(wsl_connections) = content.remote.wsl_connections.clone() {
self.wsl_connections.extend(wsl_connections)
}
self.read_ssh_config
.merge_from(&content.remote.read_ssh_config);
}
}
pub struct RemoteConnectionPrompt {
+2 -2
View File
@@ -1885,7 +1885,7 @@ impl RemoteServerProjects {
let ssh_settings = SshSettings::get_global(cx);
let mut should_rebuild = false;
let ssh_connections_changed = ssh_settings.ssh_connections.iter().ne(state
let ssh_connections_changed = ssh_settings.ssh_connections.0.iter().ne(state
.servers
.iter()
.filter_map(|server| match server {
@@ -1896,7 +1896,7 @@ impl RemoteServerProjects {
_ => None,
}));
let wsl_connections_changed = ssh_settings.wsl_connections.iter().ne(state
let wsl_connections_changed = ssh_settings.wsl_connections.0.iter().ne(state
.servers
.iter()
.filter_map(|server| match server {