From 9d378d6aa00982c565b9c19323a7882538a6063a Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Tue, 6 Feb 2018 16:53:38 +0100 Subject: [PATCH] delay 'launch' until configuration is done; address issue Microsoft/vscode#4902 --- package-lock.json | 5 +++++ package.json | 5 +++-- src/mockDebug.ts | 29 +++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8f5a4b..20ed556 100644 --- a/package-lock.json +++ b/package-lock.json @@ -133,6 +133,11 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", "dev": true }, + "await-notify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/await-notify/-/await-notify-1.0.1.tgz", + "integrity": "sha1-C0gTOyLlJBgeEVV2ZRhfKi885Hw=" + }, "aws-sign2": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", diff --git a/package.json b/package.json index d141097..c45af2a 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,9 @@ "url": "https://github.com/Microsoft/vscode-mock-debug/issues" }, "dependencies": { - "vscode-debugprotocol": "1.26.0", - "vscode-debugadapter": "1.26.0" + "await-notify": "1.0.1", + "vscode-debugadapter": "1.26.0", + "vscode-debugprotocol": "1.26.0" }, "devDependencies": { "@types/node": "7.0.43", diff --git a/src/mockDebug.ts b/src/mockDebug.ts index 4573c3a..0e24197 100644 --- a/src/mockDebug.ts +++ b/src/mockDebug.ts @@ -11,6 +11,7 @@ import { import { DebugProtocol } from 'vscode-debugprotocol'; import { basename } from 'path'; import { MockRuntime, MockBreakpoint } from './mockRuntime'; +const { Subject } = require('await-notify'); /** @@ -38,6 +39,8 @@ export class MockDebugSession extends LoggingDebugSession { private _variableHandles = new Handles(); + private _configurationDone = new Subject(); + /** * Creates a new debug adapter that is used for one debug session. * We configure the default implementation of a debug adapter here. @@ -85,11 +88,6 @@ export class MockDebugSession extends LoggingDebugSession { */ protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void { - // since this debug adapter can accept configuration requests like 'setBreakpoint' at any time, - // we request them early by sending an 'initializeRequest' to the frontend. - // The frontend will end the configuration sequence by calling 'configurationDone' request. - this.sendEvent(new InitializedEvent()); - // build and return the capabilities of this debug adapter: response.body = response.body || {}; @@ -103,13 +101,32 @@ export class MockDebugSession extends LoggingDebugSession { response.body.supportsStepBack = true; this.sendResponse(response); + + // since this debug adapter can accept configuration requests like 'setBreakpoint' at any time, + // we request them early by sending an 'initializeRequest' to the frontend. + // The frontend will end the configuration sequence by calling 'configurationDone' request. + this.sendEvent(new InitializedEvent()); + } + + /** + * Called at the end of the configuration sequence. + * Indicates that all breakpoints etc. have been sent to the DA and that the 'launch' can start. + */ + protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments): void { + super.configurationDoneRequest(response, args); + + // notify the launchRequest that configuration has finished + this._configurationDone.notify(); } - protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void { + protected async launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments) { // make sure to 'Stop' the buffered logging if 'trace' is not set logger.setup(args.trace ? Logger.LogLevel.Verbose : Logger.LogLevel.Stop, false); + // wait until configuration has finished (and configurationDoneRequest has been called) + await this._configurationDone.wait(1000); + // start the program in the runtime this._runtime.start(args.program, !!args.stopOnEntry);