Skip to content

Commit

Permalink
Expand ruff.configuration to allow inline config
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Feb 25, 2025
1 parent 45bae29 commit 3417a97
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 23 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.

2 changes: 1 addition & 1 deletion crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ enum InvalidConfigFlagReason {
ValidTomlButInvalidRuffSchema(toml::de::Error),
/// It was a valid ruff config file, but the user tried to pass a
/// value for `extend` as part of the config override.
// `extend` is special, because it affects which config files we look at
/// `extend` is special, because it affects which config files we look at
/// in the first place. We currently only parse --config overrides *after*
/// we've combined them with all the arguments from the various config files
/// that we found, so trying to override `extend` as part of a --config
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
shellexpand = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"configuration": {
"line-length": 100,
"lint": {
"extend-select": ["I001"]
},
"format": {
"quote-style": "single"
}
},
"lint": {
"extendSelect": ["RUF001"]
}
}
}
52 changes: 37 additions & 15 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use ruff_workspace::{
resolver::{ConfigurationTransformer, Relativity},
};

use crate::session::settings::{ConfigurationPreference, ResolvedEditorSettings};
use crate::session::settings::{
ConfigurationPreference, ResolvedConfiguration, ResolvedEditorSettings,
};

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

// Merge in the editor-specified configuration file, if it exists.
let editor_configuration = if let Some(config_file_path) = configuration {
tracing::debug!(
"Combining settings from editor-specified configuration file at: {}",
config_file_path.display()
);
match open_configuration_file(&config_file_path) {
Ok(config_from_file) => editor_configuration.combine(config_from_file),
err => {
tracing::error!(
"{:?}",
err.context("Unable to load editor-specified configuration file")
.unwrap_err()
// Merge in the editor-specified configuration.
let editor_configuration = if let Some(configuration) = configuration {
match configuration {
ResolvedConfiguration::FilePath(path) => {
tracing::debug!(
"Combining settings from editor-specified configuration file at: {}",
path.display()
);
match open_configuration_file(&path) {
Ok(config_from_file) => editor_configuration.combine(config_from_file),
err => {
tracing::error!(
"{:?}",
err.context("Unable to load editor-specified configuration file")
.unwrap_err()
);
editor_configuration
}
}
}
ResolvedConfiguration::Inline(options) => {
tracing::debug!(
"Combining settings from editor-specified inline configuration"
);
editor_configuration
match Configuration::from_options(options, None, project_root) {
Ok(configuration) => editor_configuration.combine(configuration),
err => {
tracing::error!(
"{:?}",
err.context("Unable to load editor-specified inline configuration")
.unwrap_err()
);
editor_configuration
}
}
}
}
} else {
Expand Down
Loading

0 comments on commit 3417a97

Please sign in to comment.