Skip to content

Commit

Permalink
ruff server reads from a configuration TOML file in the user config…
Browse files Browse the repository at this point in the history
…uration directory if no local configuration exists (#11225)

## Summary

Fixes #11158.

A settings file in the ruff user configuration directory will be used as
a configuration fallback, if it exists.

## Test Plan

Create a `pyproject.toml` or `ruff.toml` configuration file in the ruff
user configuration directory.

* On Linux, that will be `$XDG_CONFIG_HOME/ruff/` or `$HOME/.config`
* On macOS, that will be `$HOME/Library/Application Support`
* On Windows, that will be `{FOLDERID_LocalAppData}`

Then, open a file inside of a workspace with no configuration. The
settings in the user configuration file should be used.
  • Loading branch information
snowsignal authored May 1, 2024
1 parent 1f217d5 commit 068e22d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/ruff_server/src/session/workspace/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_linter::{
};
use ruff_workspace::{
configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection},
pyproject::settings_toml,
pyproject::{find_user_settings_toml, settings_toml},
resolver::{ConfigurationTransformer, Relativity},
};
use std::{
Expand Down Expand Up @@ -80,9 +80,23 @@ impl RuffSettingsIndex {
}
}

let fallback = find_user_settings_toml()
.and_then(|user_settings| {
ruff_workspace::resolver::resolve_root_settings(
&user_settings,
Relativity::Cwd,
&EditorConfigurationTransformer(editor_settings, root),
)
.ok()
})
.unwrap_or_default();

Self {
index,
fallback: Arc::default(),
fallback: Arc::new(RuffSettings {
formatter: fallback.formatter,
linter: fallback.linter,
}),
}
}

Expand Down

0 comments on commit 068e22d

Please sign in to comment.