From 5698296b53368f587b0b74b2170357c8d1d2364e Mon Sep 17 00:00:00 2001 From: Luis Gomez Date: Tue, 24 Dec 2019 14:38:50 -0300 Subject: [PATCH] Add verboseOutput option and internal logs on clients --- testSupport/package-lock.json | 2 +- testSupport/src/debugClient.ts | 8 ++++++-- testSupport/src/protocolClient.ts | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/testSupport/package-lock.json b/testSupport/package-lock.json index 37be8b8..0181e56 100644 --- a/testSupport/package-lock.json +++ b/testSupport/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-debugadapter-testsupport", - "version": "1.37.1", + "version": "1.40.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/testSupport/src/debugClient.ts b/testSupport/src/debugClient.ts index 2f06e4a..8c545b3 100644 --- a/testSupport/src/debugClient.ts +++ b/testSupport/src/debugClient.ts @@ -97,22 +97,26 @@ export class DebugClient extends ProtocolClient { this._adapterProcess = cp.spawn(this._runtime, [ this._executable ], this._spawnOptions); const sanitize = (s: string) => s.toString().replace(/\r?\n$/mg, ''); this._adapterProcess.stderr.on('data', (data: string) => { + this.log(`adapter - incoming data on stderr`); if (this._enableStderr) { - console.log(sanitize(data)); + console.log(`adapter stderr: ${sanitize(data)}`); } }); this._adapterProcess.on('error', (err) => { - console.log(err); + this.log(`adapter - error: ${err}`); reject(err); }); + this._adapterProcess.on('exit', (code: number, signal: string) => { + this.log(`adapter - exit (code ${code}, signal ${signal})`); if (code) { // done(new Error('debug adapter exit code: ' + code)); } }); this.connect(this._adapterProcess.stdout, this._adapterProcess.stdin); + this.log(`spawned debug adapter process successfully - runtime:${this._runtime}, executable:${this._executable}`); resolve(); } }); diff --git a/testSupport/src/protocolClient.ts b/testSupport/src/protocolClient.ts index 50894d1..406dac6 100644 --- a/testSupport/src/protocolClient.ts +++ b/testSupport/src/protocolClient.ts @@ -16,6 +16,7 @@ export class ProtocolClient extends ee.EventEmitter { private pendingRequests = new Map void>(); private rawData = new Buffer(0); private contentLength: number; + protected verboseOutput = false; constructor() { super(); @@ -32,6 +33,16 @@ export class ProtocolClient extends ee.EventEmitter { }); } + protected log(msg: string) { + if (this.verboseOutput) { + console.log(msg); + } + } + + public setVerboseLog(value: boolean) { + this.verboseOutput = value; + } + public send(command: 'initialize', args: DebugProtocol.InitializeRequestArguments) : Promise; public send(command: 'configurationDone', args: DebugProtocol.ConfigurationDoneArguments) : Promise; public send(command: 'launch', args: DebugProtocol.LaunchRequestArguments) : Promise; @@ -69,10 +80,13 @@ export class ProtocolClient extends ee.EventEmitter { public send(command: string, args?: any): Promise { return new Promise((completeDispatch, errorDispatch) => { + this.log(`send call on '${command}' command`) this.doSend(command, args, (result: DebugProtocol.Response) => { if (result.success) { + this.log(`send '${command}' call success`); completeDispatch(result); } else { + this.log(`send '${command}' call error: ${result.message}`) errorDispatch(new Error(result.message)); } }); @@ -94,6 +108,7 @@ export class ProtocolClient extends ee.EventEmitter { this.pendingRequests.set(request.seq, clb); const json = JSON.stringify(request); + this.log(`doSend: begin write on stream - events:${JSON.stringify(this.outputStream.eventNames())}, listeners:${JSON.stringify(this.outputStream.listeners)}'`); this.outputStream.write(`Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`, 'utf8'); }