Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4474 #4475

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/lint/latex-formatter/tex-fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading