From 60b9c1ef215fe12ec07064b71a715b5b6c6e29b8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 9 Mar 2026 15:52:35 +0000 Subject: [PATCH] feat: add VS Code output channel for debug logging and error display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace console.log/console.group calls with a named VS Code output channel ('PHPCBF'). Benefits: - Users can see debug output in 'View → Output → PHPCBF' without opening Developer Tools (Help → Toggle Developer Tools → Console), which addresses the many 'does nothing / no debug output' reports on issues #8 and #21. - The output channel auto-reveals when phpcbf encounters an error or when debug mode is enabled, so problems surface immediately. - stderr is now also captured to the output channel (was previously logged to browser console only). - The channel is registered with context.subscriptions so it is disposed when the extension deactivates. No behaviour changes for the formatter logic itself. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- extension.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/extension.js b/extension.js index 81a61ce..59e759b 100644 --- a/extension.js +++ b/extension.js @@ -15,7 +15,8 @@ const cp = require("child_process"); const TmpDir = os.tmpdir(); class PHPCBF { - constructor() { + constructor(outputChannel) { + this.outputChannel = outputChannel; this.loadSettings(); } @@ -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; } @@ -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(); @@ -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." @@ -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; @@ -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 + ")"); } }); @@ -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 => {