From 786a505dc57bb09b9aa0b835dd781b70431b9901 Mon Sep 17 00:00:00 2001 From: copilot-swe-agent <198982749+copilot-swe-agent@users.noreply.github.com> Date: Sun, 28 Dec 2025 17:04:19 +0000 Subject: [PATCH] fix(lsp): fmt.configPath empty string handling (#17425) > This PR fixes the handling of empty string values in the fmt.configPath setting for the formatter service, mirroring the fix made for the linter in PR https://github.com/oxc-project/oxc/pull/17415. When VS Code's settings UI auto-generates "fmt.configPath": "", the formatter now treats this as if no config path was specified and falls back to searching for default config files (.oxfmtrc.json and .oxfmtrc.jsonc) instead of failing to initialize. --- .../src/formatter/options.rs | 10 ++++++++++ .../src/formatter/server_formatter.rs | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/oxc_language_server/src/formatter/options.rs b/crates/oxc_language_server/src/formatter/options.rs index f624992547293..2a48148b6ef9f 100644 --- a/crates/oxc_language_server/src/formatter/options.rs +++ b/crates/oxc_language_server/src/formatter/options.rs @@ -66,4 +66,14 @@ mod test { let options = FormatOptions::try_from(json).unwrap(); assert!(options.config_path.is_none()); } + + #[test] + fn test_empty_string_config_path() { + let json = json!({ + "fmt.configPath": "" + }); + + let options = FormatOptions::try_from(json).unwrap(); + assert_eq!(options.config_path, Some(String::new())); + } } diff --git a/crates/oxc_language_server/src/formatter/server_formatter.rs b/crates/oxc_language_server/src/formatter/server_formatter.rs index ad90d15486880..5cff4a4bf3783 100644 --- a/crates/oxc_language_server/src/formatter/server_formatter.rs +++ b/crates/oxc_language_server/src/formatter/server_formatter.rs @@ -115,7 +115,7 @@ impl ServerFormatterBuilder { } fn search_config_file(root_path: &Path, config_path: Option<&String>) -> Option { - if let Some(config_path) = config_path { + if let Some(config_path) = config_path.filter(|s| !s.is_empty()) { let config = normalize_path(root_path.join(config_path)); if config.try_exists().is_ok_and(|exists| exists) { return Some(config); @@ -215,7 +215,7 @@ impl Tool for ServerFormatter { } }; - if let Some(config_path) = options.config_path.as_ref() { + if let Some(config_path) = options.config_path.as_ref().filter(|s| !s.is_empty()) { return vec![config_path.clone()]; } @@ -416,6 +416,20 @@ mod test_watchers { assert_eq!(patterns.len(), 1); assert_eq!(patterns[0], "configs/formatter.json"); } + + #[test] + fn test_empty_string_config_path() { + let patterns = Tester::new( + FAKE_DIR, + json!({ + "fmt.configPath": "" + }), + ) + .get_watcher_patterns(); + assert_eq!(patterns.len(), 2); + assert_eq!(patterns[0], ".oxfmtrc.json"); + assert_eq!(patterns[1], ".oxfmtrc.jsonc"); + } } mod handle_configuration_change {