-
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 removing all contents when formatting file with syntax error #314
Conversation
Remaining work involves:
|
We could consider applying an additional safe guard, but I'm not sure when return codes are intentionally non-zero diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py
index e1e6091..437827f 100755
--- a/ruff_lsp/server.py
+++ b/ruff_lsp/server.py
@@ -1142,7 +1142,7 @@ def _result_to_workspace_edit(
document: Document, result: RunResult | None
) -> WorkspaceEdit | None:
"""Converts a run result to a WorkspaceEdit."""
- if result is None:
+ if result is None or result.exit_code != 0:
return None
if document.kind is DocumentKind.Text: |
result = await _run_format_on_document(document) | ||
if result is None: | ||
if result is None or result.exit_code != 0: |
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 we should also add this to _lint_document_impl
for good measure.
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 the patch in #314 (comment) would apply to all uses
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.
Ahh you're right, we might exit 1 on lint errors.
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.
(In fact pretty sure we do.)
Exploring a resolution to astral-sh/ruff-vscode#336
It looks like at v0.0.42...v0.0.43#diff-9cc81288343e2240bb3387d88ab41ebf706e40c86af24cf96bad8919a48d5cceL762-L763 we no longer exit early if stdout is empty. This pull request does not restore that logic, but rather adds a return code check and exits if there is a bad return code.
Summary
ruff format
Test Plan