diff --git a/Cargo.lock b/Cargo.lock index a2b60c042e8c..9b0b565ddcc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -389,6 +389,7 @@ dependencies = [ "biome_console", "biome_diagnostics", "crossbeam", + "directories", "indexmap", "parking_lot", "rayon", @@ -1278,6 +1279,27 @@ dependencies = [ "thousands", ] +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dissimilar" version = "1.0.6" @@ -1394,7 +1416,7 @@ checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "windows-sys 0.45.0", ] @@ -1870,6 +1892,17 @@ dependencies = [ "libc", ] +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.3.1", + "libc", + "redox_syscall 0.4.1", +] + [[package]] name = "libz-sys" version = "1.1.8" @@ -2114,6 +2147,12 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "os_str_bytes" version = "6.6.1" @@ -2150,7 +2189,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "windows-sys 0.45.0", ] @@ -2474,6 +2513,26 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom 0.2.8", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.2" @@ -2928,7 +2987,7 @@ checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.2.16", "rustix 0.36.9", "windows-sys 0.42.0", ] diff --git a/crates/biome_cli/README.md b/crates/biome_cli/README.md index 8262241f8ab0..12646812f97e 100644 --- a/crates/biome_cli/README.md +++ b/crates/biome_cli/README.md @@ -6,5 +6,10 @@ and the language server interface defined in `biome_lsp` and used by the `biome` ## Logs When the server is run in daemon mode, -it will output logs to a file created in the `biome-logs` directory inside the system temporary directory. +it will output logs to a file created in the `biome-logs` directory inside the biome cache directory. +This directory is typically `~/.cache/biome` on Linux, +`C:\Users\AppData\Local\biomejs\biome\cache` on Windows, +`/Users//Library/Caches/dev.biomejs.biome` on macOS, +and the system's temporary directory on other platforms. +To obtain the precise path, execute the command `biome __print_cache_dir`. The log file will be rotated on a hourly basis. diff --git a/crates/biome_cli/src/commands/daemon.rs b/crates/biome_cli/src/commands/daemon.rs index 3de40e0947f3..2993e3b9e8c3 100644 --- a/crates/biome_cli/src/commands/daemon.rs +++ b/crates/biome_cli/src/commands/daemon.rs @@ -95,6 +95,12 @@ pub(crate) fn print_socket() -> Result<(), CliDiagnostic> { Ok(()) } +pub(crate) fn print_cache_dir() -> Result<(), CliDiagnostic> { + let cache_dir = biome_fs::ensure_cache_dir().as_path().display().to_string(); + println!("{cache_dir}"); + Ok(()) +} + pub(crate) fn lsp_proxy(config_path: Option) -> Result<(), CliDiagnostic> { let rt = Runtime::new()?; rt.block_on(start_lsp_proxy(&rt, config_path))?; @@ -202,7 +208,7 @@ fn setup_tracing_subscriber() { pub(super) fn rome_log_dir() -> PathBuf { match env::var_os("BIOME_LOG_DIR") { Some(directory) => PathBuf::from(directory), - None => env::temp_dir().join("biome-logs"), + None => biome_fs::ensure_cache_dir().join("biome-logs"), } } diff --git a/crates/biome_cli/src/commands/mod.rs b/crates/biome_cli/src/commands/mod.rs index 7ca246140065..a23ab8a8728f 100644 --- a/crates/biome_cli/src/commands/mod.rs +++ b/crates/biome_cli/src/commands/mod.rs @@ -262,6 +262,8 @@ pub enum BiomeCommand { }, #[bpaf(command("__print_socket"), hide)] PrintSocket, + #[bpaf(command("__print_cache_dir"), hide)] + PrintCacheDir, } impl BiomeCommand { @@ -279,7 +281,8 @@ impl BiomeCommand { | BiomeCommand::Stop | BiomeCommand::Init | BiomeCommand::RunServer { .. } - | BiomeCommand::PrintSocket => None, + | BiomeCommand::PrintSocket + | BiomeCommand::PrintCacheDir => None, } } @@ -297,7 +300,8 @@ impl BiomeCommand { | BiomeCommand::Stop | BiomeCommand::LspProxy(_) | BiomeCommand::RunServer { .. } - | BiomeCommand::PrintSocket => false, + | BiomeCommand::PrintSocket + | BiomeCommand::PrintCacheDir => false, } } @@ -319,7 +323,8 @@ impl BiomeCommand { | BiomeCommand::Init | BiomeCommand::LspProxy(_) | BiomeCommand::RunServer { .. } - | BiomeCommand::PrintSocket => false, + | BiomeCommand::PrintSocket + | BiomeCommand::PrintCacheDir => false, } } @@ -337,7 +342,8 @@ impl BiomeCommand { | BiomeCommand::Stop | BiomeCommand::Init | BiomeCommand::RunServer { .. } - | BiomeCommand::PrintSocket => LoggingLevel::default(), + | BiomeCommand::PrintSocket + | BiomeCommand::PrintCacheDir => LoggingLevel::default(), } } pub fn log_kind(&self) -> LoggingKind { @@ -354,7 +360,8 @@ impl BiomeCommand { | BiomeCommand::Stop | BiomeCommand::Init | BiomeCommand::RunServer { .. } - | BiomeCommand::PrintSocket => LoggingKind::default(), + | BiomeCommand::PrintSocket + | BiomeCommand::PrintCacheDir => LoggingKind::default(), } } } diff --git a/crates/biome_cli/src/lib.rs b/crates/biome_cli/src/lib.rs index 27343b4b16dd..6304d3bc23c4 100644 --- a/crates/biome_cli/src/lib.rs +++ b/crates/biome_cli/src/lib.rs @@ -191,6 +191,7 @@ impl<'app> CliSession<'app> { config_path, } => commands::daemon::run_server(stop_on_disconnect, config_path), BiomeCommand::PrintSocket => commands::daemon::print_socket(), + BiomeCommand::PrintCacheDir => commands::daemon::print_cache_dir(), }; if has_metrics { diff --git a/crates/biome_cli/src/service/unix.rs b/crates/biome_cli/src/service/unix.rs index 7475577d5a84..aed97f88e6ce 100644 --- a/crates/biome_cli/src/service/unix.rs +++ b/crates/biome_cli/src/service/unix.rs @@ -21,11 +21,11 @@ use tracing::{debug, info, Instrument}; /// Returns the filesystem path of the global socket used to communicate with /// the server daemon fn get_socket_name() -> PathBuf { - env::temp_dir().join(format!("biome-socket-{}", biome_service::VERSION)) + biome_fs::ensure_cache_dir().join(format!("biome-socket-{}", biome_service::VERSION)) } pub(crate) fn enumerate_pipes() -> io::Result> { - fs::read_dir(env::temp_dir()).map(|iter| { + fs::read_dir(biome_fs::ensure_cache_dir()).map(|iter| { iter.filter_map(|entry| { let entry = entry.ok()?.path(); let file_name = entry.file_name()?; diff --git a/crates/biome_fs/Cargo.toml b/crates/biome_fs/Cargo.toml index edcd91451f8a..508d2a7686e6 100644 --- a/crates/biome_fs/Cargo.toml +++ b/crates/biome_fs/Cargo.toml @@ -16,6 +16,7 @@ version = "0.3.1" biome_console = { workspace = true } biome_diagnostics = { workspace = true } crossbeam = "0.8.2" +directories = "5.0.1" indexmap = { workspace = true } parking_lot = { version = "0.12.0", features = ["arc_lock"] } rayon = "1.7.0" diff --git a/crates/biome_fs/src/dir.rs b/crates/biome_fs/src/dir.rs new file mode 100644 index 000000000000..e30f4ce99661 --- /dev/null +++ b/crates/biome_fs/src/dir.rs @@ -0,0 +1,21 @@ +use directories::ProjectDirs; +use std::{env, fs, path::PathBuf}; +use tracing::warn; + +pub fn ensure_cache_dir() -> PathBuf { + if let Some(proj_dirs) = ProjectDirs::from("dev", "biomejs", "biome") { + // Linux: /home/alice/.cache/biome + // Win: C:\Users\Alice\AppData\Local\biomejs\biome\cache + // Mac: /Users/Alice/Library/Caches/dev.biomejs.biome + let cache_dir = proj_dirs.cache_dir().to_path_buf(); + if let Err(err) = fs::create_dir_all(&cache_dir) { + let temp_dir = env::temp_dir(); + warn!("Failed to create local cache directory {cache_dir:?} due to error: {err}, fallback to {temp_dir:?}"); + temp_dir + } else { + cache_dir + } + } else { + env::temp_dir() + } +} diff --git a/crates/biome_fs/src/lib.rs b/crates/biome_fs/src/lib.rs index 8dd9e90a334e..f54a11902602 100644 --- a/crates/biome_fs/src/lib.rs +++ b/crates/biome_fs/src/lib.rs @@ -1,7 +1,9 @@ +mod dir; mod fs; mod interner; mod path; +pub use dir::ensure_cache_dir; pub use fs::{ AutoSearchResult, ErrorEntry, File, FileSystem, FileSystemDiagnostic, FileSystemExt, MemoryFileSystem, OpenOptions, OsFileSystem, TraversalContext, TraversalScope, BIOME_JSON, diff --git a/website/src/content/docs/guides/integrate-in-editor.mdx b/website/src/content/docs/guides/integrate-in-editor.mdx index b3cef27de377..1907869bc400 100644 --- a/website/src/content/docs/guides/integrate-in-editor.mdx +++ b/website/src/content/docs/guides/integrate-in-editor.mdx @@ -117,17 +117,16 @@ Operations via the daemon are significantly slower than the CLI itself, so it's ### Daemon logs -The Biome daemon saves logs in your file system. Logs are store in a folder called `biome-logs`. You can find this folder in the temporary directory of your operating system. +The Biome daemon saves logs in your file system. Logs are stored in a folder called `biome-logs`. The path of this folder changes based on your operative system: +- Linux: `~/.cache/biome`; +- Windows: `C:\Users\\AppData\Local\biomejs\biome\cache` +- macOS: `/Users//Library/Caches/dev.biomejs.biome` -From Windows, using a powershell: -```shell -$env:TEMP -``` - -From Linux/macOS, using a terminal: +For other operative systems, you can find the folder in the system's temporary directory. +To obtain the precise path, execute the following command: ```shell -echo $TMPDIR +biome __print_cache_dir ``` The log files are rotated on an hourly basis.