-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ruff VSCode extension erases entire file on save #9123
Comments
Let me try this now -- I thought we had fixed this but it may've regressed. |
Is this happening in every file, or only certain files? |
I assume this persists across restarting VS Code? |
Hi! Thanks very much for the quick response. This does happen across VSCode restarts -- I even restarted my laptop, was getting desperate. This is happening for every Python file that I try to save. |
Also, if you could confirm that downgrading to the previous release fixes it for you, that'd be super helpful too! |
Nice, I didn't realize you could peep on logs from particular extensions in VSCode. Here's what I see there re: version:
Scrolling through, I also see an error -- maybe this is normal, but figured I'd call it out:
Which should I try downgrading: the package (from v0.1.8 to v0.1.7) or the extension? |
Interesting, do you have |
Ahhh okay, I think the issue is: "ruff.lint.args": ["--indent-width", "4"] Or similar in your |
Aha, yeah, I have these at the bottom of my VSCode user settings -- forgot about them, since I set them up a long while back when I was still trying to figure out if
Should I remove them? Restructure the JSON as your example suggests? update: Removing them stops the files from being erased on save, but changing the structure of the json does not. |
Yeah you need to remove |
Understood. Thanks a ton for helping to resolve this so quickly! |
No prob. Sorry for all the trouble... Will get this fixed for good ASAP. |
## 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): <img width="1792" alt="Screen Shot 2023-12-13 at 10 57 20 PM" src="https://github.com/astral-sh/ruff-lsp/assets/1309177/14f70b96-5cbd-4d0f-b2a3-532984167724"> Closes astral-sh/ruff#9123
Should be fixed in the latest version, just published. |
## 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): <img width="1792" alt="Screen Shot 2023-12-13 at 10 57 20 PM" src="https://github.com/astral-sh/ruff-lsp/assets/1309177/14f70b96-5cbd-4d0f-b2a3-532984167724"> Closes astral-sh/ruff#9123
After updating/reloading a couple extensions in VSCode -- one of which may have been Ruff, I'm not 100% sure -- the Ruff extension suddenly started erasing entire Python files on save. I've disabled/re-enabled and uninstalled/re-installed, but that doesn't change the behavior. I've further narrowed it down to the "format imports" command -- "format document" does not erase the module -- but disabling the "organize imports" behavior in settings somehow does not stop saves from erasing the file. The corresponding configs in my VSCode settings and
pyproject.toml
tools have not changed.I don't have a code snippet, but I do have a gif demonstrating the phenomenon:
This is quite unexpected, and I do not understand what's gone wrong. I have the latest version of both the
ruff
VSCode extension (v2023.52.0) and Python package (v0.1.8) installed. Here's the relevant config:and
Assuming this must be user error, but gosh I don't know what or how. Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: