mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
ruff server
: Support the usage of tildes and environment variables in logFile
(#11945)
## Summary Fixes #11911. `shellexpand` is now used on `logFile` to expand the file path, allowing the usage of `~` and environment variables. ## Test Plan 1. Set `logFile` in either Neovim or Helix to a file path that needs expansion, like `~/.config/helix/ruff_logs.txt`. 2. Ensure that `RUFF_TRACE` is set to `messages` or `verbose` 3. Open a Python file in Neovim/Helix 4. Confirm that a file at the path specified was created, with the expected logs.
This commit is contained in:
parent
4c05d7a6d4
commit
c8ff89c73c
4 changed files with 41 additions and 10 deletions
|
@ -95,5 +95,7 @@ environment = { "RUFF_TRACE" = "messages" }
|
||||||
|
|
||||||
[language-server.ruff.config.settings]
|
[language-server.ruff.config.settings]
|
||||||
logLevel = "debug"
|
logLevel = "debug"
|
||||||
logFile = "/Users/developer/.cache/helix/ruff.log"
|
logFile = "~/.cache/helix/ruff.log"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `logFile` path supports tildes and environment variables.
|
||||||
|
|
|
@ -85,8 +85,10 @@ require('lspconfig').ruff.setup {
|
||||||
init_options = {
|
init_options = {
|
||||||
settings = {
|
settings = {
|
||||||
logLevel = "debug",
|
logLevel = "debug",
|
||||||
logFile = "your/log/file/path/log.txt"
|
logFile = "~/.local/state/nvim/ruff.log"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `logFile` path supports tildes and environment variables.
|
||||||
|
|
|
@ -83,6 +83,7 @@ pub(crate) struct ClientSettings {
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub(crate) struct TracingSettings {
|
pub(crate) struct TracingSettings {
|
||||||
pub(crate) log_level: Option<crate::trace::LogLevel>,
|
pub(crate) log_level: Option<crate::trace::LogLevel>,
|
||||||
|
/// Path to the log file - tildes and environment variables are supported.
|
||||||
pub(crate) log_file: Option<PathBuf>,
|
pub(crate) log_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,11 @@
|
||||||
//! A `logFile` path can also be specified in the settings, and output will be directed there instead.
|
//! A `logFile` path can also be specified in the settings, and output will be directed there instead.
|
||||||
use lsp_types::TraceValue;
|
use lsp_types::TraceValue;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::{Arc, Mutex, OnceLock};
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
str::FromStr,
|
||||||
|
sync::{Arc, Mutex, OnceLock},
|
||||||
|
};
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::{
|
use tracing_subscriber::{
|
||||||
fmt::{time::Uptime, writer::BoxMakeWriter},
|
fmt::{time::Uptime, writer::BoxMakeWriter},
|
||||||
|
@ -48,13 +52,35 @@ pub(crate) fn init_tracing(
|
||||||
.set(sender)
|
.set(sender)
|
||||||
.expect("logging sender should only be initialized once");
|
.expect("logging sender should only be initialized once");
|
||||||
|
|
||||||
let log_file = log_file.and_then(|path| {
|
let log_file = log_file
|
||||||
std::fs::OpenOptions::new()
|
.map(|path| {
|
||||||
.create(true)
|
// this expands `logFile` so that tildes and environment variables
|
||||||
.append(true)
|
// are replaced with their values, if possible.
|
||||||
.open(path)
|
if let Some(expanded) = shellexpand::full(&path.to_string_lossy())
|
||||||
.ok()
|
.ok()
|
||||||
});
|
.and_then(|path| PathBuf::from_str(&path).ok())
|
||||||
|
{
|
||||||
|
expanded
|
||||||
|
} else {
|
||||||
|
path.to_path_buf()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.and_then(|path| {
|
||||||
|
std::fs::OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(&path)
|
||||||
|
.map_err(|err| {
|
||||||
|
#[allow(clippy::print_stderr)]
|
||||||
|
{
|
||||||
|
eprintln!(
|
||||||
|
"Failed to open file at {} for logging: {err}",
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::Registry::default().with(
|
let subscriber = tracing_subscriber::Registry::default().with(
|
||||||
tracing_subscriber::fmt::layer()
|
tracing_subscriber::fmt::layer()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue