import * as vscode from "vscode" ; import { CONSTANTS , DialogResponses } from "./constants" ; import { getServerPortConfig } from "./extension_utils/utils" ; export class SimulatorDebugConfigurationProvider implements vscode . DebugConfigurationProvider { public deviceSimulatorExpressDebug : boolean ; constructor ( private pathToScript ) { this . deviceSimulatorExpressDebug = false ; } /**
     * Modify the debug configuration just before a debug session is being launched.
     */ public resolveDebugConfiguration ( folder , config , token ? ) { const activeTextEditor = vscode . window . activeTextEditor ; if ( ! config . type && ! config . request && ! config . name ) { if ( activeTextEditor && activeTextEditor . document . languageId === "python" ) { config . type = "deviceSimulatorExpress" ; config . request = "launch" ; config . name = "Device Simulator Express Debugger" ; config . console = "integratedTerminal" ; } } if ( config . type === CONSTANTS . DEBUG_CONFIGURATION_TYPE ) { this . deviceSimulatorExpressDebug = true ; if ( activeTextEditor ) { const currentFilePath = activeTextEditor . document . fileName ; if ( ! ( activeTextEditor . document . languageId === "python" ) ) { return vscode . window . showErrorMessage ( CONSTANTS . ERROR . INVALID_FILE_EXTENSION_DEBUG ) . then ( ( ) => { return undefined ; } ) ; } config . type = "python" ; config . program = this . pathToScript ; config . args = [ currentFilePath , getServerPortConfig ( ) . toString ( ) , ] ; config . rules = [ { path : this . pathToScript , include : false } , { module : "adafruit_circuitplayground" , include : false , } , { module : "playsound" , include : false } , ] ; } } if ( ! config . program ) { return vscode . window . showErrorMessage ( CONSTANTS . ERROR . NO_PROGRAM_FOUND_DEBUG ) . then ( ( ) => { return undefined ; } ) ; } return config ; } }