From 45c7f43c02faaec9057dca89e2693f4ea61d60b6 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Wed, 28 Oct 2026 11:29:03 +0800 Subject: [PATCH] fix(settings): Save SSH configurations with an empty port An unset optional field arrives as null, which TOML cannot store; such fields are now left out when writing a settings value. --- crates/ide-workspace/src/settings.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ide-workspace/src/settings.rs b/crates/ide-workspace/src/settings.rs index f814cb39..7e661697 100644 --- a/crates/ide-workspace/src/settings.rs +++ b/crates/ide-workspace/src/settings.rs @@ -98,7 +98,8 @@ fn json_to_toml(value: &Json) -> IdeResult { } Json::Object(map) => { let mut t = toml_edit::InlineTable::new(); - for (k, v) in map { + // TOML has no null: an unset optional field is left out. + for (k, v) in map.iter().filter(|(_, v)| !v.is_null()) { t.insert(k, json_to_toml(v)?); } t.into() @@ -361,6 +362,11 @@ mod tests { assert_eq!(s.files.exclude, vec!["**/dist".to_string()]); let s = store.set(SettingsScope::Global, "editor.lineHeight", json!(22.5)).unwrap(); assert_eq!(s.editor.line_height, 22.5); + // An unset optional field (null) inside an object is left out. + let ssh = json!([{ "id": "a", "name": "mac", "host": "macmini", "port": null, "user": "" }]); + let s = store.set(SettingsScope::Global, "ssh.configs", ssh).unwrap(); + assert_eq!(s.ssh.configs[0].port, None); + assert!(!std::fs::read_to_string(cfg.join("settings.toml")).unwrap().contains("port")); // Map-valued setting whose keys contain dots, replaced as a whole. let s = store .set(