From 3d72138740ed8c3ec9f733ace10fd40af0ff77eb Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Fri, 28 Feb 2025 03:58:22 -0500 Subject: [PATCH] Check `LinterSettings::preview` for version-related syntax errors (#16429) --- crates/ruff_server/src/lint.rs | 8 +++++++- crates/ruff_wasm/src/lib.rs | 8 +++++++- crates/ruff_wasm/tests/api.rs | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/ruff_server/src/lint.rs b/crates/ruff_server/src/lint.rs index 53cff99ad3..1a0a2bb597 100644 --- a/crates/ruff_server/src/lint.rs +++ b/crates/ruff_server/src/lint.rs @@ -172,6 +172,12 @@ pub(crate) fn check( ) }); + let unsupported_syntax_errors = if settings.linter.preview.is_enabled() { + parsed.unsupported_syntax_errors() + } else { + &[] + }; + let lsp_diagnostics = lsp_diagnostics.chain( show_syntax_errors .then(|| { @@ -186,7 +192,7 @@ pub(crate) fn check( encoding, ) }) - .chain(parsed.unsupported_syntax_errors().iter().map(|error| { + .chain(unsupported_syntax_errors.iter().map(|error| { unsupported_syntax_error_to_lsp_diagnostic( error, &source_kind, diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index 9949914ac0..aa0929deed 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -205,6 +205,12 @@ impl Workspace { let source_code = locator.to_source_code(); + let unsupported_syntax_errors = if self.settings.linter.preview.is_enabled() { + parsed.unsupported_syntax_errors() + } else { + &[] + }; + let messages: Vec = diagnostics .into_iter() .map(|diagnostic| { @@ -242,7 +248,7 @@ impl Workspace { fix: None, } })) - .chain(parsed.unsupported_syntax_errors().iter().map(|error| { + .chain(unsupported_syntax_errors.iter().map(|error| { let start_location = source_code.source_location(error.range.start()); let end_location = source_code.source_location(error.range.end()); diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index 650791540f..4211e6fe69 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -65,7 +65,7 @@ fn syntax_error() { fn unsupported_syntax_error() { check!( "match 2:\n case 1: ...", - r#"{}"#, + r#"{"preview": true}"#, [ExpandedMessage { code: None, message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),