mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Expand tildes when resolving Ruff server configuration file (#11283)
## Summary
Users can now include tildes and environment variables in the provided
path, just like with `--config`.
Closes #11277.
## Test Plan
Set the configuration path to `"ruff.configuration": "~/x.toml"`;
verified that the server attempted to read from `/Users/crmarsh/x.toml`.

This commit is contained in:
parent
5f0c189fa1
commit
9d45987c19
4 changed files with 11 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2373,6 +2373,7 @@ dependencies = [
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shellexpand",
|
||||||
"tracing",
|
"tracing",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
|
@ -30,12 +30,13 @@ crossbeam = { workspace = true }
|
||||||
jod-thread = { workspace = true }
|
jod-thread = { workspace = true }
|
||||||
lsp-server = { workspace = true }
|
lsp-server = { workspace = true }
|
||||||
lsp-types = { workspace = true }
|
lsp-types = { workspace = true }
|
||||||
|
regex = { workspace = true }
|
||||||
rustc-hash = { workspace = true }
|
rustc-hash = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
shellexpand = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
walkdir = { workspace = true }
|
walkdir = { workspace = true }
|
||||||
regex = { workspace = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = { workspace = true }
|
insta = { workspace = true }
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use std::{ffi::OsString, ops::Deref, path::PathBuf, str::FromStr};
|
use std::{ops::Deref, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use lsp_types::Url;
|
use lsp_types::Url;
|
||||||
use ruff_linter::{line_width::LineLength, RuleSelector};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use ruff_linter::{line_width::LineLength, RuleSelector};
|
||||||
|
|
||||||
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
||||||
pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
||||||
|
|
||||||
|
@ -234,7 +235,8 @@ impl ResolvedClientSettings {
|
||||||
settings
|
settings
|
||||||
.configuration
|
.configuration
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|config_path| OsString::from(config_path.clone()).into())
|
.and_then(|config_path| shellexpand::full(config_path).ok())
|
||||||
|
.map(|config_path| PathBuf::from(config_path.as_ref()))
|
||||||
}),
|
}),
|
||||||
lint_preview: Self::resolve_optional(all_settings, |settings| {
|
lint_preview: Self::resolve_optional(all_settings, |settings| {
|
||||||
settings.lint.as_ref()?.preview
|
settings.lint.as_ref()?.preview
|
||||||
|
@ -341,9 +343,10 @@ impl Default for InitializationOptions {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use insta::assert_debug_snapshot;
|
use insta::assert_debug_snapshot;
|
||||||
use ruff_linter::registry::Linter;
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
|
use ruff_linter::registry::Linter;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const VS_CODE_INIT_OPTIONS_FIXTURE: &str =
|
const VS_CODE_INIT_OPTIONS_FIXTURE: &str =
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Merge in the editor-specified configuration file, if it exists
|
// Merge in the editor-specified configuration file, if it exists.
|
||||||
let editor_configuration = if let Some(config_file_path) = configuration {
|
let editor_configuration = if let Some(config_file_path) = configuration {
|
||||||
match open_configuration_file(&config_file_path, project_root) {
|
match open_configuration_file(&config_file_path, project_root) {
|
||||||
Ok(config_from_file) => editor_configuration.combine(config_from_file),
|
Ok(config_from_file) => editor_configuration.combine(config_from_file),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue