From b3c0f129d88c6d937dab13811e1c1333889bc726 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Mon, 24 Oct 2022 16:37:50 +0200 Subject: [PATCH] support DAP's "restart" request --- src/mockDebug.ts | 11 +++++++++++ src/mockRuntime.ts | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/mockDebug.ts b/src/mockDebug.ts index 738e2976..4e7377b5 100644 --- a/src/mockDebug.ts +++ b/src/mockDebug.ts @@ -217,6 +217,8 @@ export class MockDebugSession extends LoggingDebugSession { response.body.supportTerminateDebuggee = true; response.body.supportsFunctionBreakpoints = true; + response.body.supportsRestartRequest = false; + this.sendResponse(response); // since this debug adapter can accept configuration requests like 'setBreakpoint' at any time, @@ -269,6 +271,15 @@ export class MockDebugSession extends LoggingDebugSession { } } + protected async restartRequest(response: DebugProtocol.RestartResponse, args0: DebugProtocol.RestartArguments, request?: DebugProtocol.Request | undefined) { + + if (args0.arguments) { + const args = args0.arguments; + await this._runtime.restart(args.program, !!args.stopOnEntry, !args.noDebug); + } + this.sendResponse(response); + } + protected setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse, args: DebugProtocol.SetFunctionBreakpointsArguments, request?: DebugProtocol.Request): void { this.sendResponse(response); } diff --git a/src/mockRuntime.ts b/src/mockRuntime.ts index 1bebfe78..244fb2e6 100644 --- a/src/mockRuntime.ts +++ b/src/mockRuntime.ts @@ -174,6 +174,25 @@ export class MockRuntime extends EventEmitter { } } + public async restart(program: string, stopOnEntry: boolean, debug: boolean): Promise { + + this.currentLine = 0; + this.currentColumn = undefined; + + if (debug) { + await this.verifyBreakpoints(this._sourceFile); + + if (stopOnEntry) { + this.findNextStatement(false, 'stopOnEntry'); + } else { + // we just start to run until we hit a breakpoint, an exception, or the end of the program + this.continue(false); + } + } else { + this.continue(false); + } + } + /** * Continue execution to the end/beginning. */