Skip to content

Commit

Permalink
delay 'launch' until configuration is done; address issue microsoft/v…
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Feb 6, 2018
1 parent c277c29 commit 9d378d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 23 additions & 6 deletions src/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { DebugProtocol } from 'vscode-debugprotocol';
import { basename } from 'path';
import { MockRuntime, MockBreakpoint } from './mockRuntime';
const { Subject } = require('await-notify');


/**
Expand Down Expand Up @@ -38,6 +39,8 @@ export class MockDebugSession extends LoggingDebugSession {

private _variableHandles = new Handles<string>();

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.
Expand Down Expand Up @@ -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 || {};

Expand All @@ -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);

Expand Down

0 comments on commit 9d378d6

Please sign in to comment.