Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use user local data dir for lsp daemon files #1238

Merged
merged 15 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
65 changes: 62 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion crates/biome_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserName>\AppData\Local\biomejs\biome\cache` on Windows,
`/Users/<UserName>/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.
8 changes: 7 additions & 1 deletion crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>) -> Result<(), CliDiagnostic> {
let rt = Runtime::new()?;
rt.block_on(start_lsp_proxy(&rt, config_path))?;
Expand Down Expand Up @@ -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"),
}
}

Expand Down
17 changes: 12 additions & 5 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ pub enum BiomeCommand {
},
#[bpaf(command("__print_socket"), hide)]
PrintSocket,
#[bpaf(command("__print_cache_dir"), hide)]
PrintCacheDir,
}

impl BiomeCommand {
Expand All @@ -279,7 +281,8 @@ impl BiomeCommand {
| BiomeCommand::Stop
| BiomeCommand::Init
| BiomeCommand::RunServer { .. }
| BiomeCommand::PrintSocket => None,
| BiomeCommand::PrintSocket
| BiomeCommand::PrintCacheDir => None,
}
}

Expand All @@ -297,7 +300,8 @@ impl BiomeCommand {
| BiomeCommand::Stop
| BiomeCommand::LspProxy(_)
| BiomeCommand::RunServer { .. }
| BiomeCommand::PrintSocket => false,
| BiomeCommand::PrintSocket
| BiomeCommand::PrintCacheDir => false,
}
}

Expand All @@ -319,7 +323,8 @@ impl BiomeCommand {
| BiomeCommand::Init
| BiomeCommand::LspProxy(_)
| BiomeCommand::RunServer { .. }
| BiomeCommand::PrintSocket => false,
| BiomeCommand::PrintSocket
| BiomeCommand::PrintCacheDir => false,
}
}

Expand All @@ -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 {
Expand All @@ -354,7 +360,8 @@ impl BiomeCommand {
| BiomeCommand::Stop
| BiomeCommand::Init
| BiomeCommand::RunServer { .. }
| BiomeCommand::PrintSocket => LoggingKind::default(),
| BiomeCommand::PrintSocket
| BiomeCommand::PrintCacheDir => LoggingKind::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/service/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<impl Iterator<Item = String>> {
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()?;
Expand Down
1 change: 1 addition & 0 deletions crates/biome_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions crates/biome_fs/src/dir.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 2 additions & 0 deletions crates/biome_fs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 3 additions & 9 deletions website/src/content/docs/guides/integrate-in-editor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,11 @@ 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 store in a folder called `biome-logs`. You can find this folder in the biome cache directory, residing at `~/.cache/biome` on Linux, `C:\Users\<UserName>\AppData\Local\biomejs\biome\cache` on Windows, `/Users/<UserName>/Library/Caches/dev.biomejs.biome` on macOS, and the system's temporary directory on other operating systems.
ematipico marked this conversation as resolved.
Show resolved Hide resolved

From Windows, using a powershell:
To obtain the precise path, execute the following command:
```shell
$env:TEMP
```

From Linux/macOS, using a terminal:

```shell
echo $TMPDIR
biome __print_cache_dir
```

The log files are rotated on an hourly basis.
Expand Down