Skip to content

Commit 4b26a73

Browse files
committed
Expand ruff.configuration to allow inline config
1 parent 4d63c16 commit 4b26a73

File tree

6 files changed

+316
-23
lines changed

6 files changed

+316
-23
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ruff/src/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ enum InvalidConfigFlagReason {
830830
ValidTomlButInvalidRuffSchema(toml::de::Error),
831831
/// It was a valid ruff config file, but the user tried to pass a
832832
/// value for `extend` as part of the config override.
833-
// `extend` is special, because it affects which config files we look at
833+
/// `extend` is special, because it affects which config files we look at
834834
/// in the first place. We currently only parse --config overrides *after*
835835
/// we've combined them with all the arguments from the various config files
836836
/// that we found, so trying to override `extend` as part of a --config

crates/ruff_server/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ serde = { workspace = true }
3838
serde_json = { workspace = true }
3939
shellexpand = { workspace = true }
4040
thiserror = { workspace = true }
41+
toml = { workspace = true }
4142
tracing = { workspace = true }
4243
tracing-subscriber = { workspace = true }
4344

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"settings": {
3+
"configuration": {
4+
"line-length": 100,
5+
"lint": {
6+
"extend-select": ["I001"]
7+
},
8+
"format": {
9+
"quote-style": "single"
10+
}
11+
},
12+
"lint": {
13+
"extendSelect": ["RUF001"]
14+
}
15+
}
16+
}

crates/ruff_server/src/session/index/ruff_settings.rs

+37-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use ruff_workspace::{
1818
resolver::{ConfigurationTransformer, Relativity},
1919
};
2020

21-
use crate::session::settings::{ConfigurationPreference, ResolvedEditorSettings};
21+
use crate::session::settings::{
22+
ConfigurationPreference, ResolvedConfiguration, ResolvedEditorSettings,
23+
};
2224

2325
#[derive(Debug)]
2426
pub struct RuffSettings {
@@ -363,21 +365,41 @@ impl ConfigurationTransformer for EditorConfigurationTransformer<'_> {
363365
..Configuration::default()
364366
};
365367

366-
// Merge in the editor-specified configuration file, if it exists.
367-
let editor_configuration = if let Some(config_file_path) = configuration {
368-
tracing::debug!(
369-
"Combining settings from editor-specified configuration file at: {}",
370-
config_file_path.display()
371-
);
372-
match open_configuration_file(&config_file_path) {
373-
Ok(config_from_file) => editor_configuration.combine(config_from_file),
374-
err => {
375-
tracing::error!(
376-
"{:?}",
377-
err.context("Unable to load editor-specified configuration file")
378-
.unwrap_err()
368+
// Merge in the editor-specified configuration.
369+
let editor_configuration = if let Some(configuration) = configuration {
370+
match configuration {
371+
ResolvedConfiguration::FilePath(path) => {
372+
tracing::debug!(
373+
"Combining settings from editor-specified configuration file at: {}",
374+
path.display()
375+
);
376+
match open_configuration_file(&path) {
377+
Ok(config_from_file) => editor_configuration.combine(config_from_file),
378+
err => {
379+
tracing::error!(
380+
"{:?}",
381+
err.context("Unable to load editor-specified configuration file")
382+
.unwrap_err()
383+
);
384+
editor_configuration
385+
}
386+
}
387+
}
388+
ResolvedConfiguration::Inline(options) => {
389+
tracing::debug!(
390+
"Combining settings from editor-specified inline configuration"
379391
);
380-
editor_configuration
392+
match Configuration::from_options(options, None, project_root) {
393+
Ok(configuration) => editor_configuration.combine(configuration),
394+
err => {
395+
tracing::error!(
396+
"{:?}",
397+
err.context("Unable to load editor-specified configuration")
398+
.unwrap_err()
399+
);
400+
editor_configuration
401+
}
402+
}
381403
}
382404
}
383405
} else {

0 commit comments

Comments
 (0)