Skip to content

Commit

Permalink
Expose stdout stream setting
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed Jul 15, 2024
1 parent b679620 commit d5f252d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'))
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/xdebugConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,11 +1134,11 @@ export class Connection extends DbgpConnection {

// ------------------------------ stream ----------------------------------------

public async sendStdout(mode: '0' | '1' | '2'): Promise<Response> {
public async sendStdout(mode: 0 | 1 | 2): Promise<Response> {
return new Response(await this._enqueueCommand('stdout', `-c ${mode}`), this)
}

public async sendStderr(mode: '0' | '1' | '2'): Promise<Response> {
public async sendStderr(mode: 0 | 1 | 2): Promise<Response> {
return new Response(await this._enqueueCommand('stderr', `-c ${mode}`), this)
}
}

0 comments on commit d5f252d

Please sign in to comment.