Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configuration inheritance for configurations specified in the LSP settings #13285

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {

// 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) {
match open_configuration_file(&config_file_path) {
Ok(config_from_file) => editor_configuration.combine(config_from_file),
Err(err) => {
tracing::error!("Unable to find editor-specified configuration file: {err}");
Expand All @@ -363,11 +363,18 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
}
}

fn open_configuration_file(
config_path: &Path,
project_root: &Path,
) -> crate::Result<Configuration> {
let options = ruff_workspace::pyproject::load_options(config_path)?;
fn open_configuration_file(config_path: &Path) -> crate::Result<Configuration> {
ruff_workspace::resolver::resolve_configuration(
config_path,
Relativity::Parent,
&IdentityTransformer,
)
}

struct IdentityTransformer;

Configuration::from_options(options, Some(config_path), project_root)
impl ConfigurationTransformer for IdentityTransformer {
fn transform(&self, config: Configuration) -> Configuration {
config
}
}
2 changes: 1 addition & 1 deletion crates/ruff_workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn find_user_settings_toml() -> Option<PathBuf> {
}

/// Load `Options` from a `pyproject.toml` or `ruff.toml` file.
pub fn load_options<P: AsRef<Path>>(path: P) -> Result<Options> {
pub(super) fn load_options<P: AsRef<Path>>(path: P) -> Result<Options> {
if path.as_ref().ends_with("pyproject.toml") {
let pyproject = parse_pyproject_toml(&path)?;
let mut ruff = pyproject
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_workspace/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub trait ConfigurationTransformer {
// configuration file extends another in the same path, we'll re-parse the same
// file at least twice (possibly more than twice, since we'll also parse it when
// resolving the "default" configuration).
fn resolve_configuration(
pub fn resolve_configuration(
pyproject: &Path,
relativity: Relativity,
transformer: &dyn ConfigurationTransformer,
Expand Down
Loading