mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
The linter and code actions can now be disabled in client settings for ruff server
(#10800)
## Summary This is a follow-up to https://github.com/astral-sh/ruff/pull/10764. Support for diagnostics, quick fixes, and source actions can now be disabled via client settings. ## Test Plan ### Manual Testing Set up your workspace as described in the test plan in https://github.com/astral-sh/ruff/pull/10764, up to step 2. You don't need to add a debug statement. The configuration for `folder_a` and `folder_b` should be as follows: `folder_a`: ```json { "ruff.codeAction.fixViolation": { "enable": true } } ``` `folder_b` ```json { "ruff.codeAction.fixViolation": { "enable": false } } ``` Finally, open up your VS Code User Settings and un-check the `Ruff > Fix All` setting. 1. Open a Python file in `folder_a` that has existing problems. The problems should be highlighted, and quick fix should be available. `source.fixAll` should not be available as a source action. 2. Open a Python file in `folder_b` that has existing problems. The problems should be highlighted, but quick fixes should not be available for any of them. `source.fixAll` should not be available as a source action. 3. Open up your VS Code Workspace Settings (second tab under the search bar) and un-check `Ruff > Lint: Enable` 4. Both files you tested in steps 1 and 2 should now lack any visible diagnostics. `source.organizeImports` should still be available as a source action.
This commit is contained in:
parent
a188ba5c26
commit
c3e28f9d55
4 changed files with 43 additions and 11 deletions
|
@ -29,18 +29,24 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
|
||||||
|
|
||||||
let supported_code_actions = supported_code_actions(params.context.only.clone());
|
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(
|
response.extend(
|
||||||
quick_fix(&snapshot, params.context.diagnostics.clone())
|
quick_fix(&snapshot, params.context.diagnostics.clone())
|
||||||
.with_failure_code(ErrorCode::InternalError)?,
|
.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)?);
|
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)?);
|
response.push(organize_imports(&snapshot).with_failure_code(ErrorCode::InternalError)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,15 @@ impl super::BackgroundDocumentRequestHandler for DocumentDiagnostic {
|
||||||
_notifier: Notifier,
|
_notifier: Notifier,
|
||||||
_params: types::DocumentDiagnosticParams,
|
_params: types::DocumentDiagnosticParams,
|
||||||
) -> Result<DocumentDiagnosticReportResult> {
|
) -> Result<DocumentDiagnosticReportResult> {
|
||||||
let diagnostics = crate::lint::check(
|
let diagnostics = if snapshot.client_settings().lint() {
|
||||||
snapshot.document(),
|
crate::lint::check(
|
||||||
&snapshot.configuration().linter,
|
snapshot.document(),
|
||||||
snapshot.encoding(),
|
&snapshot.configuration().linter,
|
||||||
);
|
snapshot.encoding(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
};
|
||||||
|
|
||||||
Ok(DocumentDiagnosticReportResult::Report(
|
Ok(DocumentDiagnosticReportResult::Report(
|
||||||
types::DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
|
types::DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
|
||||||
|
|
|
@ -36,7 +36,6 @@ pub(crate) struct Session {
|
||||||
pub(crate) struct DocumentSnapshot {
|
pub(crate) struct DocumentSnapshot {
|
||||||
configuration: Arc<RuffConfiguration>,
|
configuration: Arc<RuffConfiguration>,
|
||||||
resolved_client_capabilities: Arc<ResolvedClientCapabilities>,
|
resolved_client_capabilities: Arc<ResolvedClientCapabilities>,
|
||||||
#[allow(dead_code)]
|
|
||||||
client_settings: settings::ResolvedClientSettings,
|
client_settings: settings::ResolvedClientSettings,
|
||||||
document_ref: DocumentRef,
|
document_ref: DocumentRef,
|
||||||
position_encoding: PositionEncoding,
|
position_encoding: PositionEncoding,
|
||||||
|
@ -217,6 +216,10 @@ impl DocumentSnapshot {
|
||||||
&self.resolved_client_capabilities
|
&self.resolved_client_capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn client_settings(&self) -> &ResolvedClientSettings {
|
||||||
|
&self.client_settings
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn document(&self) -> &DocumentRef {
|
pub(crate) fn document(&self) -> &DocumentRef {
|
||||||
&self.document_ref
|
&self.document_ref
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,13 @@ pub(crate) type WorkspaceSettingsMap = FxHashMap<Url, ClientSettings>;
|
||||||
/// sends them.
|
/// sends them.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||||
// TODO(jane): Remove dead code warning
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
#[allow(dead_code, clippy::struct_excessive_bools)]
|
|
||||||
pub(crate) struct ResolvedClientSettings {
|
pub(crate) struct ResolvedClientSettings {
|
||||||
fix_all: bool,
|
fix_all: bool,
|
||||||
organize_imports: bool,
|
organize_imports: bool,
|
||||||
lint_enable: bool,
|
lint_enable: bool,
|
||||||
|
// TODO(jane): Remove once noqa auto-fix is implemented
|
||||||
|
#[allow(dead_code)]
|
||||||
disable_rule_comment_enable: bool,
|
disable_rule_comment_enable: bool,
|
||||||
fix_violation_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 {
|
impl Default for InitializationOptions {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::GlobalOnly { settings: None }
|
Self::GlobalOnly { settings: None }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue