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

ruff server: Resolve configuration for each document individually #10950

Merged
merged 11 commits into from
Apr 16, 2024
Merged
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.

1 change: 1 addition & 0 deletions crates/ruff_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }
walkdir = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl super::SyncNotificationHandler for DidChangeWatchedFiles {
) -> Result<()> {
for change in params.changes {
session
.reload_configuration(&change.uri)
.reload_ruff_settings(&change.uri)
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_server/src/server/api/requests/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn fix_all(snapshot: &DocumentSnapshot) -> crate::Result<CodeActionOrCommand> {
document,
snapshot.resolved_client_capabilities(),
snapshot.url(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
snapshot.encoding(),
document.version(),
)?),
Expand Down Expand Up @@ -140,7 +140,7 @@ fn organize_imports(snapshot: &DocumentSnapshot) -> crate::Result<CodeActionOrCo
document,
snapshot.resolved_client_capabilities(),
snapshot.url(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
document.version(),
)?),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl super::BackgroundDocumentRequestHandler for CodeActionResolve {
document,
snapshot.resolved_client_capabilities(),
snapshot.url(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
document.version(),
)
Expand All @@ -56,7 +56,7 @@ impl super::BackgroundDocumentRequestHandler for CodeActionResolve {
document,
snapshot.resolved_client_capabilities(),
snapshot.url(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
document.version(),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_server/src/server/api/requests/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl super::BackgroundDocumentRequestHandler for DocumentDiagnostic {
let diagnostics = if snapshot.client_settings().lint() {
crate::lint::check(
snapshot.document(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
)
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_server/src/server/api/requests/execute_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl super::SyncRequestHandler for ExecuteCommand {
Command::FixAll => {
let edits = super::code_action_resolve::fix_all_edit(
snapshot.document(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
)
.with_failure_code(ErrorCode::InternalError)?;
Expand All @@ -83,7 +83,7 @@ impl super::SyncRequestHandler for ExecuteCommand {
Command::OrganizeImports => {
let edits = super::code_action_resolve::organize_imports_edit(
snapshot.document(),
&snapshot.configuration().linter,
&snapshot.ruff_settings().linter,
snapshot.encoding(),
)
.with_failure_code(ErrorCode::InternalError)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_server/src/server/api/requests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl super::BackgroundDocumentRequestHandler for Format {
pub(super) fn format_document(snapshot: &DocumentSnapshot) -> Result<super::FormatResponse> {
let doc = snapshot.document();
let source = doc.contents();
let formatted = crate::format::format(doc, &snapshot.configuration().formatter)
let formatted = crate::format::format(doc, &snapshot.ruff_settings().formatter)
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
// fast path - if the code is the same, return early
if formatted == source {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_server/src/server/api/requests/format_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl super::BackgroundDocumentRequestHandler for FormatRange {
let index = document.index();
let range = params.range.to_text_range(text, index, snapshot.encoding());
let formatted_range =
crate::format::format_range(document, &snapshot.configuration().formatter, range)
crate::format::format_range(document, &snapshot.ruff_settings().formatter, range)
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
Ok(Some(vec![types::TextEdit {
range: formatted_range
Expand Down