Skip to content

Commit 5a2e65b

Browse files
dinocostaematipico
andauthored
fix(json): detect global Zed settings as JSONC on macOS and Windows (#10730)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent 53c6efc commit 5a2e65b

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed an issue where Biome was resolving [the well-known Zed settings file](https://biomejs.dev/guides/configure-biome/#well-known-files) from the wrong location on macOS and Windows.

crates/biome_languages/src/json.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use camino::Utf8Path;
44
use core::str;
55
use directories::ProjectDirs;
66
use std::fmt::{Display, Formatter};
7+
use std::path::PathBuf;
78
use std::str::FromStr;
89

910
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
@@ -281,7 +282,7 @@ impl JsonFileSource {
281282
return Ok(Self::json_allow_comments_and_trailing_commas(extension));
282283
}
283284

284-
if zed_global_directory().is_some_and(|dir| path.starts_with(dir.config_dir()))
285+
if zed_global_directory().is_some_and(|dir| path.starts_with(&dir))
285286
|| vscode_global_directory().is_some_and(|dir| path.starts_with(dir.config_dir()))
286287
|| cursor_global_directory().is_some_and(|dir| path.starts_with(dir.config_dir()))
287288
{
@@ -365,8 +366,12 @@ fn vscode_global_directory() -> Option<ProjectDirs> {
365366
ProjectDirs::from("", "Code", "User")
366367
}
367368

368-
fn zed_global_directory() -> Option<ProjectDirs> {
369-
ProjectDirs::from("", "", "zed")
369+
fn zed_global_directory() -> Option<PathBuf> {
370+
cfg_select! {
371+
target_os = "macos" => directories::BaseDirs::new().map(|dirs| dirs.home_dir().join(".config").join("zed")) ,
372+
target_os = "windows" => directories::BaseDirs::new().map(|dirs| dirs.config_dir().join("Zed")),
373+
_ => directories::ProjectDirs::from("", "", "zed").map(|dirs| dirs.config_dir().to_path_buf())
374+
}
370375
}
371376

372377
#[cfg(test)]
@@ -395,10 +400,21 @@ mod tests {
395400

396401
#[test]
397402
fn test_global_zed_settings() {
398-
let path = zed_global_directory()
399-
.expect("Failed to get config directory")
400-
.config_dir()
401-
.join("settings.json");
403+
let dir = zed_global_directory().expect("Failed to get config directory");
404+
405+
#[cfg(target_os = "macos")]
406+
{
407+
let base = directories::BaseDirs::new().expect("Failed to get base dirs");
408+
assert_eq!(dir, base.home_dir().join(".config").join("zed"));
409+
}
410+
411+
#[cfg(target_os = "windows")]
412+
{
413+
let base = directories::BaseDirs::new().expect("Failed to get base dirs");
414+
assert_eq!(dir, base.config_dir().join("Zed"));
415+
}
416+
417+
let path = dir.join("settings.json");
402418
let path = Utf8Path::from_path(path.as_path()).expect("Failed to create Utf8Path");
403419
let file_source =
404420
JsonFileSource::try_from_well_known(path).expect("Failed to create JsonFileSource");

0 commit comments

Comments
 (0)