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

Server: Allow FixAll action in presence of version-specific syntax errors #16848

Merged
merged 7 commits into from
Mar 20, 2025

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Mar 19, 2025

The single flag has_syntax_error on LinterResult is replaced with two (private) flags: has_valid_syntax and has_no_unsupported_syntax_errors, which record whether there are ParseErrors or UnsupportedSyntaxErrors, respectively. Only the former is used to prevent a FixAll action.

An attempt has been made to make consistent the usage of the phrases "valid syntax" (which seems to be used to refer only to parser errors) and "syntax error" (which refers to both parser errors and version-specific syntax errors).

Remark for review: crates/ruff/src/diagnostics.rs is actually a small diff, not sure what happened there. If you pull it down locally and git diff --ignore-all-space it looks better.

Closes #16841

Test:

Screen.Recording.2025-03-19.at.9.30.51.AM.mov

dylwil3 added 5 commits March 19, 2025 09:57

Unverified

The email in this signature doesn’t match the committer email.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Unverified

The email in this signature doesn’t match the committer email.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@dylwil3 dylwil3 added bug Something isn't working server Related to the LSP server labels Mar 19, 2025
@dylwil3 dylwil3 requested review from ntBre and dhruvmanila March 19, 2025 15:09
Copy link
Contributor

github-actions bot commented Mar 19, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this, LGTM! Just need to propagate the changes to the fuzz crate it looks like.

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.

Thanks for the quick fix!

I think we should explore an alternate option to avoid the duplication here as a follow-up.

has_no_unsupported_syntax_errors: bool,
}

impl LinterResult {
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit unfortunate that these methods need to be repeated on both Parsed and LinterResult. We could explore another approach to avoid duplication, not necessarily in this PR, that utilizes bitflags for these two booleans like SyntaxFlags that can then be queried to ask whether there are parse errors or unsupported syntax errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - the current approach seems like it'd be easy for the two to fall out of sync

@dhruvmanila
Copy link
Member

One minor nit: we mainly use the [...] syntax for rule categories so I'd avoid using "[server]" and instead just use "Server: " in the PR title.

@dylwil3 dylwil3 changed the title [server] Allow FixAll action in presence of version-specific syntax errors Server: Allow FixAll action in presence of version-specific syntax errors Mar 20, 2025
@dylwil3 dylwil3 merged commit 74f64d3 into astral-sh:main Mar 20, 2025
22 checks passed
dcreager added a commit that referenced this pull request Mar 21, 2025
* main: (26 commits)
  Use the common `OperatorPrecedence` for the parser (#16747)
  [red-knot] Check subtype relation between callable types (#16804)
  [red-knot] Check whether two callable types are equivalent (#16698)
  [red-knot] Ban most `Type::Instance` types in type expressions (#16872)
  Special-case value-expression inference of special form subscriptions (#16877)
  [syntax-errors] Fix star annotation before Python 3.11 (#16878)
  Recognize `SyntaxError:` as an error code for ecosystem checks (#16879)
  [red-knot] add test cases result in false positive errors (#16856)
  Bump 0.11.1 (#16871)
  Allow discovery of venv in VIRTUAL_ENV env variable (#16853)
  Split git pathspecs in change determination onto separate lines (#16869)
  Use the correct base commit for change determination (#16857)
  Separate `BitXorOr` into `BitXor` and `BitOr` precedence (#16844)
  Server: Allow `FixAll` action in presence of version-specific syntax errors (#16848)
  [`refurb`] Fix starred expressions fix (`FURB161`) (#16550)
  [`flake8-executable`] Add pytest and uv run to help message for `shebang-missing-python` (`EXE003`) (#16855)
  Show more precise messages in invalid type expressions (#16850)
  [`flake8-executables`] Allow `uv run` in shebang line for `shebang-missing-python` (`EXE003`) (#16849)
  Add `--exit-non-zero-on-format` (#16009)
  [red-knot] Ban list literals in most contexts in type expressions (#16847)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Organize imports not working due to version-specific syntax errors
3 participants