diff --git a/package.json b/package.json index 107e0641..ba783cb5 100644 --- a/package.json +++ b/package.json @@ -366,6 +366,17 @@ "xdebugCloudToken": { "type": "string", "description": "Xdebug Could token" + }, + "stream": { + "type": "object", + "description": "Xdebug stream settings", + "properties": { + "stdout": { + "type": "number", + "description": "Redirect stdout stream: 0 (disable), 1 (copy), 2 (redirect)", + "default": 0 + } + } } } } diff --git a/src/phpDebug.ts b/src/phpDebug.ts index ac741a39..5fc152f2 100644 --- a/src/phpDebug.ts +++ b/src/phpDebug.ts @@ -98,6 +98,10 @@ export interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchReques maxConnections?: number /** Xdebug cloud token */ xdebugCloudToken?: string + /** Xdebug stream settings */ + stream?: { + stdout?: 0 | 1 | 2 + } // CLI options @@ -561,8 +565,10 @@ class PhpDebugSession extends vscode.DebugSession { throw new Error(`Error applying xdebugSettings: ${String(error instanceof Error ? error.message : error)}`) } - if (this._args.externalConsole) { - await connection.sendStdout('1') + const stdout = + this._args.stream?.stdout === undefined ? (this._args.externalConsole ? 1 : 0) : this._args.stream.stdout + if (stdout) { + await connection.sendStdout(stdout) connection.on('stream', (stream: xdebug.Stream) => this.sendEvent(new vscode.OutputEvent(stream.value, 'stdout')) ) diff --git a/src/test/adapter.ts b/src/test/adapter.ts index 14acdd2e..f343b03a 100644 --- a/src/test/adapter.ts +++ b/src/test/adapter.ts @@ -828,7 +828,7 @@ describe('PHP Debug Adapter', () => { it('listen with externalConsole', async () => { // this is how we can currently turn on stdout redirect - await Promise.all([client.launch({ externalConsole: true }), client.configurationSequence()]) + await Promise.all([client.launch({ stream: { stdout: '1' } }), client.configurationSequence()]) const script = childProcess.spawn('php', [program]) after(() => script.kill()) diff --git a/src/xdebugConnection.ts b/src/xdebugConnection.ts index 35d93413..1df7e760 100644 --- a/src/xdebugConnection.ts +++ b/src/xdebugConnection.ts @@ -1134,11 +1134,11 @@ export class Connection extends DbgpConnection { // ------------------------------ stream ---------------------------------------- - public async sendStdout(mode: '0' | '1' | '2'): Promise { + public async sendStdout(mode: 0 | 1 | 2): Promise { return new Response(await this._enqueueCommand('stdout', `-c ${mode}`), this) } - public async sendStderr(mode: '0' | '1' | '2'): Promise { + public async sendStderr(mode: 0 | 1 | 2): Promise { return new Response(await this._enqueueCommand('stderr', `-c ${mode}`), this) } }