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 fdb332c
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit fdb332c

Please sign in to comment.