-
Notifications
You must be signed in to change notification settings - Fork 46
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
Avoid erasing files when Ruff fails with an error #341
Conversation
87ffc37
to
e2f7590
Compare
ruff_lsp/server.py
Outdated
# For `ruff check`, 0 indicates successful completion with no remaining | ||
# diagnostics, 1 indicates successful completion with remaining diagnostics, | ||
# and 2 indicates an error. | ||
if result.exit_code != 0 and result.exit_code != 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't know what's more idiomatic Python
if result.exit_code != 0 and result.exit_code != 1: | |
if not result.exit_code in [0, 1]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
if result.exit_code not in [0, 1]:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not in (0, 1)
is most idiomatic, probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
if result.exit_code not in [0, 1]: ...
Python's hard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha both work!
e2f7590
to
5ccbb89
Compare
There was a problem hiding this 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! It works on Notebook as expected.
Summary
A user reported an issue in the VS Code extension (astral-sh/ruff#9123) in which their files were being erased on-save. The issue is that we don't check the exit code of all commands, and so if
ruff check
fails with an error, then we end up wiping the file entirely.This PR adds exit code-checking for all commands in the LSP. Further, we now surface such failures to the user directly (see bottom right):
Closes astral-sh/ruff#9123