import { Logger } from "../shared/logger" ; import * as vscode from "vscode" ; export class Debugger { public constructor ( private readonly logger ) { } public async manageVSCodeDebuggingSession ( workspace , debuggerConfiguration ) { if ( vscode . debug . activeDebugSession ) { return ; } let currentSession ; currentSession = await this . startDebuggingSession ( workspace , currentSession , debuggerConfiguration ) ; if ( ! currentSession ) { this . logger . error ( "No active debug session - aborting" ) ; return ; } const subscription = vscode . debug . onDidTerminateDebugSession ( ( session ) => { if ( currentSession !== session ) { return ; } this . logger . info ( "Debug session ended" ) ; subscription . dispose ( ) ; } ) ; } private async startDebuggingSession ( workspace , currentSession , debuggerConfiguration ) { const workspaceFolder = vscode . workspace . getWorkspaceFolder ( workspace . uri ) ; await vscode . debug . startDebugging ( workspaceFolder , debuggerConfiguration ) ; await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ; currentSession = vscode . debug . activeDebugSession ; return currentSession ; } }