Skip to content

Commit

Permalink
Expand tildes when resolving Ruff server configuration file (#11283)
Browse files Browse the repository at this point in the history
## 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`.

![Screenshot 2024-05-04 at 1 31
43 PM](https://github.com/astral-sh/ruff/assets/1309177/ea9829cd-6d8a-4818-a47c-dcff9219e996)
  • Loading branch information
charliermarsh committed May 4, 2024
1 parent 5f0c189 commit 9d45987
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/ruff_server/Cargo.toml
Expand Up @@ -30,12 +30,13 @@ crossbeam = { workspace = true }
jod-thread = { workspace = true }
lsp-server = { workspace = true }
lsp-types = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
shellexpand = { workspace = true }
tracing = { workspace = true }
walkdir = { workspace = true }
regex = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions crates/ruff_server/src/session/settings.rs
@@ -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>;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_server/src/session/workspace/ruff_settings.rs
Expand Up @@ -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),
Expand Down

0 comments on commit 9d45987

Please sign in to comment.