From ba1633ffc78f82b0d37bc2e2fdd30fa7c3a20607 Mon Sep 17 00:00:00 2001 From: panoanx Date: Sun, 13 Oct 2024 14:30:14 +0800 Subject: [PATCH] fix: stringify chunk before merging chunks breaks character at the end --- src/lint/latex-formatter/latexindent.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lint/latex-formatter/latexindent.ts b/src/lint/latex-formatter/latexindent.ts index 1469fda94..da53266ec 100644 --- a/src/lint/latex-formatter/latexindent.ts +++ b/src/lint/latex-formatter/latexindent.ts @@ -156,15 +156,19 @@ function format(document: vscode.TextDocument, range?: vscode.Range): Thenable stdoutBuffer.push(chunk.toString())) - worker.stderr.on('data', (chunk: Buffer | string) => stderrBuffer.push(chunk.toString())) + const stdoutBuffer: Buffer[] = [] + const stderrBuffer: Buffer[] = [] + worker.stdout.on('data', (chunk: Buffer | string) => { + stdoutBuffer.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)) + }) + worker.stderr.on('data', (chunk: Buffer | string) => { + stderrBuffer.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)) + }) worker.on('error', err => { removeTemporaryFiles() void logger.showErrorMessage('Formatting failed. Please refer to LaTeX Workshop Output for details.') logger.log(`Formatting failed: ${err.message}`) - logger.log(`stderr: ${stderrBuffer.join('')}`) + logger.log(`stderr: ${Buffer.concat(stderrBuffer).toString()}`) resolve(undefined) }) worker.on('close', code => { @@ -172,10 +176,10 @@ function format(document: vscode.TextDocument, range?: vscode.Range): Thenable