@@ -76,7 +76,7 @@ interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArgume
7676 program ?: string
7777 /** Optional arguments passed to the debuggee. */
7878 args ?: string [ ]
79- /** Launch the debuggee in this working directory (specified as an absolute path). If omitted the debuggee is lauched in its own directory. */
79+ /** Launch the debuggee in this working directory (specified as an absolute path). If omitted the debuggee is launched in its own directory. */
8080 cwd ?: string
8181 /** Absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. */
8282 runtimeExecutable ?: string
@@ -105,9 +105,6 @@ class PhpDebugSession extends vscode.DebugSession {
105105 */
106106 private _connections = new Map < number , xdebug . Connection > ( )
107107
108- /** A set of connections which are not yet running and are waiting for configurationDoneRequest */
109- private _waitingConnections = new Set < xdebug . Connection > ( )
110-
111108 /** A counter for unique source IDs */
112109 private _sourceIdCounter = 1
113110
@@ -147,6 +144,9 @@ class PhpDebugSession extends vscode.DebugSession {
147144 /** Breakpoint Manager to map VS Code to Xdebug breakpoints */
148145 private _breakpointManager = new BreakpointManager ( )
149146
147+ /** Breakpoint Adapters */
148+ private _breakpointAdapters = new Map < xdebug . Connection , BreakpointAdapter > ( )
149+
150150 public constructor ( ) {
151151 super ( )
152152 this . setDebuggerColumnsStartAt1 ( true )
@@ -188,6 +188,8 @@ class PhpDebugSession extends vscode.DebugSession {
188188 supportTerminateDebuggee : true ,
189189 }
190190 this . sendResponse ( response )
191+ // request breakpoints right away
192+ this . sendEvent ( new vscode . InitializedEvent ( ) )
191193 }
192194
193195 protected attachRequest (
@@ -271,7 +273,6 @@ class PhpDebugSession extends vscode.DebugSession {
271273 this . sendEvent ( new vscode . OutputEvent ( 'new connection ' + connection . id + '\n' ) , true )
272274 }
273275 this . _connections . set ( connection . id , connection )
274- this . _waitingConnections . add ( connection )
275276 const disposeConnection = ( error ?: Error ) => {
276277 if ( this . _connections . has ( connection . id ) ) {
277278 if ( args . log ) {
@@ -288,7 +289,8 @@ class PhpDebugSession extends vscode.DebugSession {
288289 this . sendEvent ( new vscode . ThreadEvent ( 'exited' , connection . id ) )
289290 connection . close ( )
290291 this . _connections . delete ( connection . id )
291- this . _waitingConnections . delete ( connection )
292+ this . _statuses . delete ( connection )
293+ this . _breakpointAdapters . delete ( connection )
292294 }
293295 }
294296 connection . on ( 'warning' , ( warning : string ) => {
@@ -336,8 +338,19 @@ class PhpDebugSession extends vscode.DebugSession {
336338
337339 let bpa = new BreakpointAdapter ( connection , this . _breakpointManager )
338340 bpa . on ( 'dapEvent' , event => this . sendEvent ( event ) )
339- // request breakpoints from VS Code
340- await this . sendEvent ( new vscode . InitializedEvent ( ) )
341+ this . _breakpointAdapters . set ( connection , bpa )
342+ // sync breakpoints to connection
343+ await bpa . process ( )
344+ let xdebugResponse : xdebug . StatusResponse
345+ // either tell VS Code we stopped on entry or run the script
346+ if ( this . _args . stopOnEntry ) {
347+ // do one step to the first statement
348+ this . _hasStoppedOnEntry = false
349+ xdebugResponse = await connection . sendStepIntoCommand ( )
350+ } else {
351+ xdebugResponse = await connection . sendRunCommand ( )
352+ }
353+ this . _checkStatus ( xdebugResponse )
341354 } catch ( error ) {
342355 this . sendEvent (
343356 new vscode . OutputEvent ( ( error instanceof Error ? error . message : error ) + '\n' , 'stderr' )
@@ -383,9 +396,16 @@ class PhpDebugSession extends vscode.DebugSession {
383396 this . _checkStatus ( response )
384397 } else if ( response . status === 'stopped' ) {
385398 this . _connections . delete ( connection . id )
399+ this . _statuses . delete ( connection )
400+ this . _breakpointAdapters . delete ( connection )
386401 this . sendEvent ( new vscode . ThreadEvent ( 'exited' , connection . id ) )
387402 connection . close ( )
388403 } else if ( response . status === 'break' ) {
404+ // First sync breakpoints
405+ let bpa = this . _breakpointAdapters . get ( connection )
406+ if ( bpa ) {
407+ await bpa . process ( )
408+ }
389409 // StoppedEvent reason can be 'step', 'breakpoint', 'exception' or 'pause'
390410 let stoppedEventReason : 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry'
391411 let exceptionText : string | undefined
@@ -418,7 +438,6 @@ class PhpDebugSession extends vscode.DebugSession {
418438 )
419439 event . body . allThreadsStopped = false
420440 this . sendEvent ( event )
421- this . _breakpointManager . process ( )
422441 }
423442 }
424443
@@ -530,35 +549,10 @@ class PhpDebugSession extends vscode.DebugSession {
530549 response : VSCodeDebugProtocol . ConfigurationDoneResponse ,
531550 args : VSCodeDebugProtocol . ConfigurationDoneArguments
532551 ) {
533- let xdebugResponses : xdebug . StatusResponse [ ] = [ ]
534- try {
535- xdebugResponses = await Promise . all < xdebug . StatusResponse > (
536- Array . from ( this . _waitingConnections ) . map ( connection => {
537- this . _waitingConnections . delete ( connection )
538- // either tell VS Code we stopped on entry or run the script
539- if ( this . _args . stopOnEntry ) {
540- // do one step to the first statement
541- this . _hasStoppedOnEntry = false
542- return connection . sendStepIntoCommand ( )
543- } else {
544- return connection . sendRunCommand ( )
545- }
546- } )
547- )
548- } catch ( error ) {
549- this . sendErrorResponse ( response , < Error > error )
550- for ( const response of xdebugResponses ) {
551- this . _checkStatus ( response )
552- }
553- return
554- }
555552 this . sendResponse ( response )
556- for ( const response of xdebugResponses ) {
557- this . _checkStatus ( response )
558- }
559553 }
560554
561- /** Executed after a successfull launch or attach request and after a ThreadEvent */
555+ /** Executed after a successful launch or attach request and after a ThreadEvent */
562556 protected threadsRequest ( response : VSCodeDebugProtocol . ThreadsResponse ) : void {
563557 // PHP doesn't have threads, but it may have multiple requests in parallel.
564558 // Think about a website that makes multiple, parallel AJAX requests to your PHP backend.
@@ -952,7 +946,8 @@ class PhpDebugSession extends vscode.DebugSession {
952946 }
953947 await connection . close ( )
954948 this . _connections . delete ( id )
955- this . _waitingConnections . delete ( connection )
949+ this . _statuses . delete ( connection )
950+ this . _breakpointAdapters . delete ( connection )
956951 } )
957952 )
958953 // If listening for connections, close server
0 commit comments