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

Check LinterSettings::preview for version-related syntax errors #16429

Merged
merged 3 commits into from
Feb 28, 2025

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 28, 2025

Summary

Fixes part of the report in #16417 (comment) by checking LinterSettings::preview in both the language server and in the playground. That now covers all calls of Parsed::unsupported_syntax_errors.

Test Plan

Manual tests in both VS Code and the playground. I also added preview = true to the WASM test I added earlier.

Summary
--
Fixes part of the report in
#16417 (comment) by checking
`LinterSettings::preview` in both the language server and in the playground.
That now covers all calls of `Parsed::unsupported_syntax_errors`.

Test Plan
--
Manual tests in both VS Code and the playground. I also added `preview = true`
to the WASM test I added earlier.
@ntBre ntBre added the bug Something isn't working label Feb 28, 2025
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment on lines +175 to +180
let unsupported_syntax_errors = if settings.linter.preview.is_enabled() {
parsed.unsupported_syntax_errors()
} else {
&[]
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this into check_path as that seems like the common denominator for the server, WASM, and the command-line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that might not be possible in the server because it needs to know whether the user has enabled showSyntaxErrors or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think you're right. I kept putting it right next to the message/diagnostic generation code, but I think we could just truncate the vec inside of check_path because it's called right before each of these. I'll just have to add a new Parsed method because the field itself is private.

I don't think we can move this exact code unless we return an additional unsupported_syntax_errors from check_path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that might not be possible in the server because it needs to know whether the user has enabled showSyntaxErrors or not

I think we could pass a ShowSyntaxErrors enum similar to flags::Noqa to check_path which in combination with the settings.preview.is_enabled() check be used to filter out syntax error diagnostics. But, ShowSyntaxErrors would need to be defined in ruff_linter as it can't be in ruff_server because otherwise it would create circular dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of unifying the handling if it doesn't introduce a lot of complexity but I think we can ship the bug fix as is. That gives us more time to explore the refactor and allows us to ship the bugfix sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might just leave this alone for now if it's okay with you both. I looked into it briefly today and realized that my parsed.unsupported_syntax_errors.truncate() idea would require a &mut Parsed, which I didn't really want to add. There are four of these calls, which is annoying, but we'll also get to simply delete them all once the feature is out of preview.

Another temporary option could be passing a preview: bool (or enum) argument to the unsupported_syntax_errors method to avoid duplicating the explicit ifs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into it. I think it's fine to leave it as is.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking this on quickly and fixing it.

@ntBre
Copy link
Contributor Author

ntBre commented Feb 28, 2025

Thanks for the quick review! I'd also like to get #16425 merged and then we could probably do a release if you want. That should cover all of the (known) bugs with the version-related errors.

I'm going to take a look at your suggestion in the morning, though. It's getting pretty late

@MichaReiser MichaReiser merged commit 3d72138 into main Feb 28, 2025
21 checks passed
@MichaReiser MichaReiser deleted the brent/preview-syntax-errors branch February 28, 2025 08:58
dcreager added a commit that referenced this pull request Feb 28, 2025
* main:
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
dcreager added a commit that referenced this pull request Feb 28, 2025
* dcreager/alist-type:
  Remove unneeded shear override
  Update property test CI
  Move alist into red_knot_python_semantic
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
ntBre added a commit that referenced this pull request Mar 19, 2025
Summary
--

This PR updates `check_path` in the `ruff_linter` crate to return a
`Vec<Message>` instead of a `Vec<Diagnostic>`. The main motivation for
this is to make it easier to convert semantic syntax errors directly
into `Message`s rather than `Diagnostic`s in #16106. However, this also
has the benefit of keeping the preview check on unsupported syntax
errors in `check_path`, as suggested in
#16429 (comment).

All of the interesting changes are in the first commit. The second
commit just renames variables like `diagnostics` to `messages`, and the
third commit is a tiny import fix.

I also updated the `ExpandedMessage::location` field name, which caused
a few extra commits tidying up the playground code. I thought it was
nicely symmetric with `end_location`, but I'm happy to revert that too.

Test Plan
--

Existing tests. I also tested the playground and server manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants