mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Directly include Settings
struct for the server (#16042)
## Summary This PR refactors the `RuffSettings` struct to directly include the resolved `Settings` instead of including the specific fields from it. The server utilizes a lot of it already, so it makes sense to just include the entire struct for simplicity. ### `Deref` I implemented `Deref` on `RuffSettings` to return the `Settings` because `RuffSettings` is now basically a wrapper around it with the config path as the other field. This path field is only used for debugging ("printDebugInformation" command).
This commit is contained in:
parent
b54e390cb4
commit
cc0a5dd14a
6 changed files with 37 additions and 76 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
@ -6,12 +7,11 @@ use std::sync::Arc;
|
|||
use anyhow::Context;
|
||||
use ignore::{WalkBuilder, WalkState};
|
||||
|
||||
use ruff_linter::settings::types::UnsafeFixes;
|
||||
use ruff_linter::{
|
||||
display_settings, fs::normalize_path_to, settings::types::FilePattern,
|
||||
settings::types::PreviewMode,
|
||||
fs::normalize_path_to, settings::types::FilePattern, settings::types::PreviewMode,
|
||||
};
|
||||
use ruff_workspace::resolver::match_exclusion;
|
||||
use ruff_workspace::Settings;
|
||||
use ruff_workspace::{
|
||||
configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection},
|
||||
pyproject::{find_user_settings_toml, settings_toml},
|
||||
|
@ -24,14 +24,16 @@ pub struct RuffSettings {
|
|||
/// The path to this configuration file, used for debugging.
|
||||
/// The default fallback configuration does not have a file path.
|
||||
path: Option<PathBuf>,
|
||||
/// Toggle for unsafe fixes.
|
||||
unsafe_fixes: UnsafeFixes,
|
||||
/// Settings used to manage file inclusion and exclusion.
|
||||
file_resolver: ruff_workspace::FileResolverSettings,
|
||||
/// Settings to pass into the Ruff linter.
|
||||
linter: ruff_linter::settings::LinterSettings,
|
||||
/// Settings to pass into the Ruff formatter.
|
||||
formatter: ruff_workspace::FormatterSettings,
|
||||
/// The resolved settings.
|
||||
settings: Settings,
|
||||
}
|
||||
|
||||
impl Deref for RuffSettings {
|
||||
type Target = Settings;
|
||||
|
||||
fn deref(&self) -> &Settings {
|
||||
&self.settings
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct RuffSettingsIndex {
|
||||
|
@ -42,15 +44,7 @@ pub(super) struct RuffSettingsIndex {
|
|||
|
||||
impl std::fmt::Display for RuffSettings {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
display_settings! {
|
||||
formatter = f,
|
||||
fields = [
|
||||
self.file_resolver,
|
||||
self.linter,
|
||||
self.formatter
|
||||
]
|
||||
}
|
||||
Ok(())
|
||||
std::fmt::Display::fmt(&self.settings, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,32 +74,9 @@ impl RuffSettings {
|
|||
|
||||
RuffSettings {
|
||||
path,
|
||||
unsafe_fixes: fallback.unsafe_fixes,
|
||||
file_resolver: fallback.file_resolver,
|
||||
formatter: fallback.formatter,
|
||||
linter: fallback.linter,
|
||||
settings: fallback,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the [`ruff_workspace::FileResolverSettings`] for this [`RuffSettings`].
|
||||
pub(crate) fn file_resolver(&self) -> &ruff_workspace::FileResolverSettings {
|
||||
&self.file_resolver
|
||||
}
|
||||
|
||||
/// Return the [`ruff_linter::settings::LinterSettings`] for this [`RuffSettings`].
|
||||
pub(crate) fn linter(&self) -> &ruff_linter::settings::LinterSettings {
|
||||
&self.linter
|
||||
}
|
||||
|
||||
/// Return the [`ruff_workspace::FormatterSettings`] for this [`RuffSettings`].
|
||||
pub(crate) fn formatter(&self) -> &ruff_workspace::FormatterSettings {
|
||||
&self.formatter
|
||||
}
|
||||
|
||||
/// Return the [`UnsafeFixes`] for this [`RuffSettings`].
|
||||
pub(crate) fn unsafe_fixes(&self) -> UnsafeFixes {
|
||||
self.unsafe_fixes
|
||||
}
|
||||
}
|
||||
|
||||
impl RuffSettingsIndex {
|
||||
|
@ -152,10 +123,7 @@ impl RuffSettingsIndex {
|
|||
directory.to_path_buf(),
|
||||
Arc::new(RuffSettings {
|
||||
path: Some(pyproject),
|
||||
unsafe_fixes: settings.unsafe_fixes,
|
||||
file_resolver: settings.file_resolver,
|
||||
linter: settings.linter,
|
||||
formatter: settings.formatter,
|
||||
settings,
|
||||
}),
|
||||
);
|
||||
break;
|
||||
|
@ -210,7 +178,7 @@ impl RuffSettingsIndex {
|
|||
// Add any settings within the workspace itself
|
||||
let mut builder = WalkBuilder::new(root);
|
||||
builder.standard_filters(
|
||||
respect_gitignore.unwrap_or_else(|| fallback.file_resolver().respect_gitignore),
|
||||
respect_gitignore.unwrap_or_else(|| fallback.file_resolver.respect_gitignore),
|
||||
);
|
||||
builder.hidden(false);
|
||||
builder.threads(
|
||||
|
@ -277,10 +245,7 @@ impl RuffSettingsIndex {
|
|||
directory,
|
||||
Arc::new(RuffSettings {
|
||||
path: Some(pyproject),
|
||||
unsafe_fixes: settings.unsafe_fixes,
|
||||
file_resolver: settings.file_resolver,
|
||||
linter: settings.linter,
|
||||
formatter: settings.formatter,
|
||||
settings,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue