mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-13 17:26:53 +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
|
|
@ -93,7 +93,7 @@ pub(super) fn fix_all_edit(
|
|||
query: &DocumentQuery,
|
||||
encoding: PositionEncoding,
|
||||
) -> crate::Result<Fixes> {
|
||||
crate::fix::fix_all(query, query.settings().linter(), encoding)
|
||||
crate::fix::fix_all(query, &query.settings().linter, encoding)
|
||||
}
|
||||
|
||||
pub(super) fn resolve_edit_for_organize_imports(
|
||||
|
|
@ -110,7 +110,7 @@ pub(super) fn organize_imports_edit(
|
|||
query: &DocumentQuery,
|
||||
encoding: PositionEncoding,
|
||||
) -> crate::Result<Fixes> {
|
||||
let mut linter_settings = query.settings().linter().clone();
|
||||
let mut linter_settings = query.settings().linter.clone();
|
||||
linter_settings.rules = [
|
||||
Rule::UnsortedImports, // I001
|
||||
Rule::MissingRequiredImport, // I002
|
||||
|
|
|
|||
|
|
@ -82,15 +82,14 @@ fn format_text_document(
|
|||
encoding: PositionEncoding,
|
||||
is_notebook: bool,
|
||||
) -> Result<super::FormatResponse> {
|
||||
let file_resolver_settings = query.settings().file_resolver();
|
||||
let formatter_settings = query.settings().formatter();
|
||||
let settings = query.settings();
|
||||
|
||||
// If the document is excluded, return early.
|
||||
if let Some(file_path) = query.file_path() {
|
||||
if is_document_excluded_for_formatting(
|
||||
&file_path,
|
||||
file_resolver_settings,
|
||||
formatter_settings,
|
||||
&settings.file_resolver,
|
||||
&settings.formatter,
|
||||
text_document.language_id(),
|
||||
) {
|
||||
return Ok(None);
|
||||
|
|
@ -98,7 +97,7 @@ fn format_text_document(
|
|||
}
|
||||
|
||||
let source = text_document.contents();
|
||||
let formatted = crate::format::format(text_document, query.source_type(), formatter_settings)
|
||||
let formatted = crate::format::format(text_document, query.source_type(), &settings.formatter)
|
||||
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
|
||||
let Some(mut formatted) = formatted else {
|
||||
return Ok(None);
|
||||
|
|
|
|||
|
|
@ -46,15 +46,14 @@ fn format_text_document_range(
|
|||
query: &DocumentQuery,
|
||||
encoding: PositionEncoding,
|
||||
) -> Result<super::FormatResponse> {
|
||||
let file_resolver_settings = query.settings().file_resolver();
|
||||
let formatter_settings = query.settings().formatter();
|
||||
let settings = query.settings();
|
||||
|
||||
// If the document is excluded, return early.
|
||||
if let Some(file_path) = query.file_path() {
|
||||
if is_document_excluded_for_formatting(
|
||||
&file_path,
|
||||
file_resolver_settings,
|
||||
formatter_settings,
|
||||
&settings.file_resolver,
|
||||
&settings.formatter,
|
||||
text_document.language_id(),
|
||||
) {
|
||||
return Ok(None);
|
||||
|
|
@ -67,7 +66,7 @@ fn format_text_document_range(
|
|||
let formatted_range = crate::format::format_range(
|
||||
text_document,
|
||||
query.source_type(),
|
||||
formatter_settings,
|
||||
&settings.formatter,
|
||||
range,
|
||||
)
|
||||
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue