Skip to content
Draft
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
16 changes: 16 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,23 @@ class PHPCBF {
exec.stdin.end();
}

// Kill the subprocess if it does not exit within 30 seconds. This
// prevents VS Code from hanging indefinitely when phpcbf stalls
// (e.g. waiting for stdin on a misconfigured build, or processing an
// unusually large file). The timeout is cleared on normal exit.
const TIMEOUT_MS = 30000;
let killTimer = setTimeout(() => {
exec.kill();
fs.unlink(fileName, function() {});
window.showErrorMessage(
"PHPCBF: timed out after " + (TIMEOUT_MS / 1000) + " s. " +
"Check executablePath and that phpcbf can run on this file."
);
}, TIMEOUT_MS);

let promise = new Promise((resolve, reject) => {
exec.on("error", err => {
clearTimeout(killTimer);
reject();
console.log(err);
if (err.code == "ENOENT") {
Expand All @@ -164,6 +179,7 @@ class PHPCBF {
}
});
exec.on("exit", code => {
clearTimeout(killTimer);
/* phpcbf exit codes:
Exit code 0 is used to indicate that no fixable errors were found, so nothing was fixed
Exit code 1 is used to indicate that all fixable errors were fixed correctly
Expand Down