Skip to content

Commit

Permalink
Do not erase code when format command returns empty result (#115)
Browse files Browse the repository at this point in the history
Resolves #114 

Together with anoma/juvix#2205
  • Loading branch information
vrom911 authored Jun 19, 2023
1 parent 2a15f2e commit 2d81e34
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2d81e34

Please sign in to comment.