Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/oxc_language_server/src/formatter/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
18 changes: 16 additions & 2 deletions crates/oxc_language_server/src/formatter/server_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl ServerFormatterBuilder {
}

fn search_config_file(root_path: &Path, config_path: Option<&String>) -> Option<PathBuf> {
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);
Expand Down Expand Up @@ -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()];
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading