From f3f8696b277c6113b0d199129e8c423a9a0d9266 Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Fri, 24 May 2024 15:13:31 -0700 Subject: [PATCH 1/3] Properly search parent directories for project configuration --- crates/ruff_server/src/session/index/ruff_settings.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ruff_server/src/session/index/ruff_settings.rs b/crates/ruff_server/src/session/index/ruff_settings.rs index e54b16020bc3f..e7b9d3f10ccba 100644 --- a/crates/ruff_server/src/session/index/ruff_settings.rs +++ b/crates/ruff_server/src/session/index/ruff_settings.rs @@ -4,7 +4,7 @@ use ruff_linter::{ }; use ruff_workspace::{ configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection}, - pyproject::{find_user_settings_toml, settings_toml}, + pyproject::{find_settings_toml, find_user_settings_toml}, resolver::{ConfigurationTransformer, Relativity}, }; use std::{ @@ -88,7 +88,11 @@ impl RuffSettingsIndex { .filter(|entry| entry.file_type().is_dir()) .map(DirEntry::into_path) { - if let Some(pyproject) = settings_toml(&directory).ok().flatten() { + if let Some(pyproject) = find_settings_toml(&directory).ok().flatten() { + if index.contains_key(&pyproject) { + continue; + } + let Ok(settings) = ruff_workspace::resolver::resolve_root_settings( &pyproject, Relativity::Parent, From aa12a562dc83a4077a2318ec85a0e005f0198c08 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 26 May 2024 14:05:13 -0400 Subject: [PATCH 2/3] Traverse ancestors directly --- .../src/session/index/ruff_settings.rs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/ruff_server/src/session/index/ruff_settings.rs b/crates/ruff_server/src/session/index/ruff_settings.rs index e7b9d3f10ccba..47ef8f0a24bcb 100644 --- a/crates/ruff_server/src/session/index/ruff_settings.rs +++ b/crates/ruff_server/src/session/index/ruff_settings.rs @@ -4,7 +4,7 @@ use ruff_linter::{ }; use ruff_workspace::{ configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection}, - pyproject::{find_settings_toml, find_user_settings_toml}, + pyproject::{find_user_settings_toml, settings_toml}, resolver::{ConfigurationTransformer, Relativity}, }; use std::{ @@ -82,17 +82,35 @@ impl RuffSettingsIndex { pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self { let mut index = BTreeMap::default(); + // Add any settings from above the workspace root. + for directory in root.ancestors() { + if let Some(pyproject) = settings_toml(directory).ok().flatten() { + let Ok(settings) = ruff_workspace::resolver::resolve_root_settings( + &pyproject, + Relativity::Parent, + &EditorConfigurationTransformer(editor_settings, root), + ) else { + continue; + }; + index.insert( + directory.to_path_buf(), + Arc::new(RuffSettings { + linter: settings.linter, + formatter: settings.formatter, + }), + ); + break; + } + } + + // Add any settings within the workspace itself. for directory in WalkDir::new(root) .into_iter() .filter_map(Result::ok) .filter(|entry| entry.file_type().is_dir()) .map(DirEntry::into_path) { - if let Some(pyproject) = find_settings_toml(&directory).ok().flatten() { - if index.contains_key(&pyproject) { - continue; - } - + if let Some(pyproject) = settings_toml(&directory).ok().flatten() { let Ok(settings) = ruff_workspace::resolver::resolve_root_settings( &pyproject, Relativity::Parent, From 5d661749d592ca947b04eabb794e7fed717931f0 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 26 May 2024 14:07:02 -0400 Subject: [PATCH 3/3] Re-add index check --- crates/ruff_server/src/session/index/ruff_settings.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ruff_server/src/session/index/ruff_settings.rs b/crates/ruff_server/src/session/index/ruff_settings.rs index 47ef8f0a24bcb..628b6eddce9b9 100644 --- a/crates/ruff_server/src/session/index/ruff_settings.rs +++ b/crates/ruff_server/src/session/index/ruff_settings.rs @@ -85,6 +85,10 @@ impl RuffSettingsIndex { // Add any settings from above the workspace root. for directory in root.ancestors() { if let Some(pyproject) = settings_toml(directory).ok().flatten() { + if index.contains_key(&pyproject) { + continue; + } + let Ok(settings) = ruff_workspace::resolver::resolve_root_settings( &pyproject, Relativity::Parent, @@ -111,6 +115,10 @@ impl RuffSettingsIndex { .map(DirEntry::into_path) { if let Some(pyproject) = settings_toml(&directory).ok().flatten() { + if index.contains_key(&pyproject) { + continue; + } + let Ok(settings) = ruff_workspace::resolver::resolve_root_settings( &pyproject, Relativity::Parent,