From fdb332ce1f0a174577c7576b9818721ac16931ac Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 9 Nov 2023 22:33:03 -0500 Subject: [PATCH] Avoid writing empty source on excluded files --- ruff_lsp/server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py index e1e6091..c3bbe4e 100755 --- a/ruff_lsp/server.py +++ b/ruff_lsp/server.py @@ -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: @@ -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")