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
33 changes: 19 additions & 14 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const cp = require("child_process");
const TmpDir = os.tmpdir();

class PHPCBF {
constructor() {
constructor(outputChannel) {
this.outputChannel = outputChannel;
this.loadSettings();
}

Expand Down Expand Up @@ -95,10 +96,8 @@ class PHPCBF {
args.push("--standard=" + this.standard);
}
if (this.debug) {
console.group("PHPCBF");
console.log(
"PHPCBF args: " + this.executablePath + " " + args.join(" ")
);
this.outputChannel.appendLine("PHPCBF args: " + this.executablePath + " " + args.join(" "));
this.outputChannel.show(true);
}
return args;
}
Expand Down Expand Up @@ -153,7 +152,7 @@ class PHPCBF {
this.loadSettings(document.uri);

if (this.debug) {
console.time("phpcbf");
this.outputChannel.appendLine("[" + new Date().toISOString() + "] Formatting: " + document.fileName);
}
let text = document.getText();

Expand All @@ -176,7 +175,8 @@ class PHPCBF {
let promise = new Promise((resolve, reject) => {
exec.on("error", err => {
reject();
console.log(err);
this.outputChannel.appendLine("PHPCBF error: " + err.message);
this.outputChannel.show(true);
if (err.code == "ENOENT") {
window.showErrorMessage(
"PHPCBF: " + err.message + ". executablePath not found."
Expand All @@ -190,6 +190,9 @@ class PHPCBF {
Exit code 2 is used to indicate that PHPCBF failed to fix some of the fixable errors it found
Exit code 3 is used for general script execution errors
*/
if (this.debug) {
this.outputChannel.appendLine("PHPCBF exit code: " + code);
}
switch (code) {
case 0:
break;
Expand Down Expand Up @@ -223,23 +226,22 @@ class PHPCBF {

if (phpcbfError) {
exec.stdout.on("data", buffer => {
console.log(buffer.toString());
this.outputChannel.appendLine("PHPCBF: " + buffer.toString());
this.outputChannel.show(true);
window.showErrorMessage(buffer.toString());
});
}
if (this.debug) {
exec.stdout.on("data", buffer => {
console.log(buffer.toString());
this.outputChannel.appendLine(buffer.toString());
});
}
exec.stderr.on("data", buffer => {
console.log(buffer.toString());
this.outputChannel.appendLine("PHPCBF stderr: " + buffer.toString());
});
exec.on("close", code => {
// console.log(code);
if (this.debug) {
console.timeEnd("phpcbf");
console.groupEnd();
this.outputChannel.appendLine("PHPCBF done (exit " + code + ")");
}
});

Expand Down Expand Up @@ -279,7 +281,10 @@ class PHPCBF {
}

exports.activate = context => {
let phpcbf = new PHPCBF();
const outputChannel = window.createOutputChannel("PHPCBF");
context.subscriptions.push(outputChannel);

let phpcbf = new PHPCBF(outputChannel);

context.subscriptions.push(
workspace.onWillSaveTextDocument(event => {
Expand Down