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

Avoid writing empty source on excluded files #317

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ async def format_document(params: DocumentFormattingParams) -> list[TextEdit] |
document = Document.from_cell_or_text_uri(params.text_document.uri)

result = await _run_format_on_document(document)
if result is None or result.exit_code != 0:
if result is None or result.exit_code:
return None

if not result.stdout and document.source.strip():
return None

if document.kind is DocumentKind.Cell:
Expand Down Expand Up @@ -1145,6 +1148,9 @@ def _result_to_workspace_edit(
if result is None:
return None

if not result.stdout and document.source.strip():
return None

if document.kind is DocumentKind.Text:
edits = _fixed_source_to_edits(
original_source=document.source, fixed_source=result.stdout.decode("utf-8")
Expand Down
Loading