mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28: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,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 ruff_linter::{line_width::LineLength, RuleSelector};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
use ruff_linter::{line_width::LineLength, RuleSelector};
|
||||
|
||||
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
||||
pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
||||
|
||||
|
@ -234,7 +235,8 @@ impl ResolvedClientSettings {
|
|||
settings
|
||||
.configuration
|
||||
.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| {
|
||||
settings.lint.as_ref()?.preview
|
||||
|
@ -341,9 +343,10 @@ impl Default for InitializationOptions {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use insta::assert_debug_snapshot;
|
||||
use ruff_linter::registry::Linter;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use ruff_linter::registry::Linter;
|
||||
|
||||
use super::*;
|
||||
|
||||
const VS_CODE_INIT_OPTIONS_FIXTURE: &str =
|
||||
|
|
|
@ -165,7 +165,7 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
|
|||
..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 {
|
||||
match open_configuration_file(&config_file_path, project_root) {
|
||||
Ok(config_from_file) => editor_configuration.combine(config_from_file),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue