Skip to content

Commit

Permalink
Avoid writing empty source on excluded files
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 10, 2023
1 parent 7c42733 commit 94ae4a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ async def apply_format(arguments: tuple[TextDocument]):
document = Document.from_uri(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 != 0 or not result.stdout:
return None

workspace_edit = _result_to_workspace_edit(document, result)
Expand All @@ -1114,7 +1114,7 @@ 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 != 0 or not result.stdout:
return None

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

if not result.stdout:
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

0 comments on commit 94ae4a4

Please sign in to comment.