@@ -82,6 +82,9 @@ export class PythonDebugger extends DebugSession {
8282
8383 private startDebugServer ( ) : Promise < IDebugServer > {
8484 let programDirectory = this . launchArgs ? path . dirname ( this . launchArgs . program ) : this . attachArgs . localRoot ;
85+ if ( typeof this . launchArgs . cwd === 'string' && this . launchArgs . cwd . length > 0 ) {
86+ programDirectory = this . launchArgs . cwd ;
87+ }
8588 this . pythonProcess = new PythonProcess ( 0 , "" , programDirectory ) ;
8689 this . debugServer = this . debugClient . CreateDebugServer ( this . pythonProcess ) ;
8790 this . InitializeEventHandlers ( ) ;
@@ -178,8 +181,16 @@ export class PythonDebugger extends DebugSession {
178181 }
179182 protected launchRequest ( response : DebugProtocol . LaunchResponse , args : LaunchRequestArguments ) : void {
180183 // Confirm the file exists
181- if ( ! fs . existsSync ( args . program ) ) {
182- return this . sendErrorResponse ( response , 2001 , `File does not exist. "${ args . program } "` ) ;
184+ if ( typeof args . module !== 'string' || args . module . length === 0 ) {
185+ if ( ! fs . existsSync ( args . program ) ) {
186+ return this . sendErrorResponse ( response , 2001 , `File does not exist. "${ args . program } "` ) ;
187+ }
188+ }
189+ else {
190+ // When using modules ensure the cwd has been provided
191+ if ( typeof args . cwd !== 'string' || args . cwd . length === 0 ) {
192+ return this . sendErrorResponse ( response , 2001 , `'cwd' in 'launch.json' needs to point to the working directory` ) ;
193+ }
183194 }
184195 this . sendEvent ( new TelemetryEvent ( telemetryContracts . Debugger . Load , {
185196 Debug_Console : args . console ,
0 commit comments