diff --git a/crates/ruff_server/src/server/api/requests/code_action.rs b/crates/ruff_server/src/server/api/requests/code_action.rs index 0fa462cd2b..0d697b0e59 100644 --- a/crates/ruff_server/src/server/api/requests/code_action.rs +++ b/crates/ruff_server/src/server/api/requests/code_action.rs @@ -29,18 +29,24 @@ impl super::BackgroundDocumentRequestHandler for CodeActions { let supported_code_actions = supported_code_actions(params.context.only.clone()); - if supported_code_actions.contains(&SupportedCodeAction::QuickFix) { + if snapshot.client_settings().fix_violation() + && supported_code_actions.contains(&SupportedCodeAction::QuickFix) + { response.extend( quick_fix(&snapshot, params.context.diagnostics.clone()) .with_failure_code(ErrorCode::InternalError)?, ); } - if supported_code_actions.contains(&SupportedCodeAction::SourceFixAll) { + if snapshot.client_settings().fix_all() + && supported_code_actions.contains(&SupportedCodeAction::SourceFixAll) + { response.push(fix_all(&snapshot).with_failure_code(ErrorCode::InternalError)?); } - if supported_code_actions.contains(&SupportedCodeAction::SourceOrganizeImports) { + if snapshot.client_settings().organize_imports() + && supported_code_actions.contains(&SupportedCodeAction::SourceOrganizeImports) + { response.push(organize_imports(&snapshot).with_failure_code(ErrorCode::InternalError)?); } diff --git a/crates/ruff_server/src/server/api/requests/diagnostic.rs b/crates/ruff_server/src/server/api/requests/diagnostic.rs index 634f111f86..e72245f201 100644 --- a/crates/ruff_server/src/server/api/requests/diagnostic.rs +++ b/crates/ruff_server/src/server/api/requests/diagnostic.rs @@ -19,11 +19,15 @@ impl super::BackgroundDocumentRequestHandler for DocumentDiagnostic { _notifier: Notifier, _params: types::DocumentDiagnosticParams, ) -> Result { - let diagnostics = crate::lint::check( - snapshot.document(), - &snapshot.configuration().linter, - snapshot.encoding(), - ); + let diagnostics = if snapshot.client_settings().lint() { + crate::lint::check( + snapshot.document(), + &snapshot.configuration().linter, + snapshot.encoding(), + ) + } else { + vec![] + }; Ok(DocumentDiagnosticReportResult::Report( types::DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport { diff --git a/crates/ruff_server/src/session.rs b/crates/ruff_server/src/session.rs index bf8bb2efc8..72580c3a30 100644 --- a/crates/ruff_server/src/session.rs +++ b/crates/ruff_server/src/session.rs @@ -36,7 +36,6 @@ pub(crate) struct Session { pub(crate) struct DocumentSnapshot { configuration: Arc, resolved_client_capabilities: Arc, - #[allow(dead_code)] client_settings: settings::ResolvedClientSettings, document_ref: DocumentRef, position_encoding: PositionEncoding, @@ -217,6 +216,10 @@ impl DocumentSnapshot { &self.resolved_client_capabilities } + pub(crate) fn client_settings(&self) -> &ResolvedClientSettings { + &self.client_settings + } + pub(crate) fn document(&self) -> &DocumentRef { &self.document_ref } diff --git a/crates/ruff_server/src/session/settings.rs b/crates/ruff_server/src/session/settings.rs index b6e831b1d0..a29692a63c 100644 --- a/crates/ruff_server/src/session/settings.rs +++ b/crates/ruff_server/src/session/settings.rs @@ -12,12 +12,13 @@ pub(crate) type WorkspaceSettingsMap = FxHashMap; /// sends them. #[derive(Debug)] #[cfg_attr(test, derive(PartialEq, Eq))] -// TODO(jane): Remove dead code warning -#[allow(dead_code, clippy::struct_excessive_bools)] +#[allow(clippy::struct_excessive_bools)] pub(crate) struct ResolvedClientSettings { fix_all: bool, organize_imports: bool, lint_enable: bool, + // TODO(jane): Remove once noqa auto-fix is implemented + #[allow(dead_code)] disable_rule_comment_enable: bool, fix_violation_enable: bool, } @@ -196,6 +197,24 @@ impl ResolvedClientSettings { } } +impl ResolvedClientSettings { + pub(crate) fn fix_all(&self) -> bool { + self.fix_all + } + + pub(crate) fn organize_imports(&self) -> bool { + self.organize_imports + } + + pub(crate) fn lint(&self) -> bool { + self.lint_enable + } + + pub(crate) fn fix_violation(&self) -> bool { + self.fix_violation_enable + } +} + impl Default for InitializationOptions { fn default() -> Self { Self::GlobalOnly { settings: None }