Skip to content
Snippets Groups Projects
Unverified Commit 6b37c0d5 authored by James Jianqiao Yu's avatar James Jianqiao Yu Committed by GitHub
Browse files

Merge pull request #4475 from shinyypig/master

fix #4474
parents 39e25b9a 3e2f2bf2
No related branches found
No related tags found
No related merge requests found
......@@ -42,10 +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))
})
})
process.stdin?.write(document.getText(range))
process.stdin?.end()
const edits = await promise
// 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;
if (edits) {
edits.newText = endsWithNewline ? edits.newText : edits.newText.replace(/\n$/, '');
}
return edits
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment