From 2d81e3462ae83150191d3fe1ccddfcd450f989fb Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Mon, 19 Jun 2023 15:58:21 +0100 Subject: [PATCH] Do not erase code when format command returns empty result (#115) Resolves #114 Together with https://github.com/anoma/juvix/pull/2205 --- src/formatter.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/formatter.ts b/src/formatter.ts index 7ce72ce..5c14cdc 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -7,7 +7,6 @@ import { config } from './config'; import { logger } from './utils/debug'; export function activate(_context: vscode.ExtensionContext) { - vscode.languages.registerDocumentFormattingEditProvider('Juvix', { provideDocumentFormattingEdits( document: vscode.TextDocument @@ -35,7 +34,9 @@ export function activate(_context: vscode.ExtensionContext) { if (ls.status == 0) { const stdout = ls.stdout; - return [vscode.TextEdit.replace(range, stdout)]; + // in case of the empty return from the format command, do nothing + // this is the way to protect from unexpected behaviour of the `format` command + return stdout !== '' ? [vscode.TextEdit.replace(range, stdout)] : []; } else { const errMsg: string = ls.stderr.toString(); logger.warn(errMsg);