From 60d8b38ed6da575e925fef632b18226865c8bd6d Mon Sep 17 00:00:00 2001 From: James Yu Date: Sat, 7 Dec 2024 23:20:42 +0800 Subject: [PATCH] Code format of #4475 --- src/lint/latex-formatter/tex-fmt.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lint/latex-formatter/tex-fmt.ts b/src/lint/latex-formatter/tex-fmt.ts index 20cd1be21..a7cb7e0cf 100644 --- a/src/lint/latex-formatter/tex-fmt.ts +++ b/src/lint/latex-formatter/tex-fmt.ts @@ -42,15 +42,15 @@ async function formatDocument(document: vscode.TextDocument, range?: vscode.Rang resolve(vscode.TextEdit.replace(range ?? document.validateRange(new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE)), stdoutStr)) }) }) - + // 2024-12-4, for tex-fmt 0.4.7, when using `--stdin`, it requires a newline at the end of the input; Therefore, we need to add a newline at the end of the input if it doesn't exist, and remove it from the output if it exists. - const text = document.getText(range); - const endsWithNewline = text.endsWith('\n'); - process.stdin?.write(endsWithNewline ? text : text + '\n'); - process.stdin?.end(); - const edits = await promise; + const text = document.getText(range) + const endsWithNewline = text.endsWith('\n') + process.stdin?.write(endsWithNewline ? text : text + '\n') + process.stdin?.end() + const edits = await promise if (edits) { - edits.newText = endsWithNewline ? edits.newText : edits.newText.replace(/\n$/, ''); + edits.newText = endsWithNewline ? edits.newText : edits.newText.replace(/\n$/, '') } return edits }