Skip to content

Commit

Permalink
fix: stringify chunk before merging chunks breaks character at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
panoanx committed Oct 13, 2024
1 parent f940943 commit ba1633f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lint/latex-formatter/latexindent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,30 @@ function format(document: vscode.TextDocument, range?: vscode.Range): Thenable<v
logger.logCommand('Formatting LaTeX.', formatter, args)
const worker = cs.spawn(formatter, args, { stdio: 'pipe', cwd: documentDirectory })
// handle stdout/stderr
const stdoutBuffer: string[] = []
const stderrBuffer: string[] = []
worker.stdout.on('data', (chunk: Buffer | string) => 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 => {
removeTemporaryFiles()
if (code !== 0) {
void logger.showErrorMessage('Formatting failed. Please refer to LaTeX Workshop Output for details.')
logger.log(`Formatting failed with exit code ${code}`)
logger.log(`stderr: ${stderrBuffer.join('')}`)
logger.log(`stderr: ${Buffer.concat(stderrBuffer).toString()}`)
return resolve(undefined)
}
const stdout = stdoutBuffer.join('')
const stdout = Buffer.concat(stdoutBuffer).toString()
if (stdout !== '') {
const edit = vscode.TextEdit.replace(range ?? document.validateRange(new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE)), stdout)
logger.log('Formatted ' + document.fileName)
Expand Down

0 comments on commit ba1633f

Please sign in to comment.