@@ -90,14 +90,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
9090 public constructor ( ) {
9191 super ( ) ;
9292
93- const api = new AtelierAPI ( ) ;
94- this . cookies = api . cookies ;
95- if ( ! api . active ) {
96- throw new Error ( "Connection not active" ) ;
97- }
98- this . _namespace = api . ns ;
99- this . _url = api . xdebugUrl ( ) ;
100-
10193 // this debugger uses zero-based lines and columns
10294 this . setDebuggerLinesStartAt1 ( false ) ;
10395 this . setDebuggerColumnsStartAt1 ( false ) ;
@@ -117,27 +109,37 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
117109 supportsStepBack : false ,
118110 } ;
119111
120- const socket = new WebSocket ( this . _url , {
121- headers : {
122- cookie : this . cookies ,
123- } ,
124- } ) ;
112+ try {
113+ const api = new AtelierAPI ( ) ;
114+ this . cookies = api . cookies ;
115+ if ( ! api . active ) {
116+ throw new Error ( "Connection not active" ) ;
117+ }
118+ this . _namespace = api . ns ;
119+ this . _url = api . xdebugUrl ( ) ;
125120
126- const disposeConnection = ( error ?: Error ) : void => {
127- this . sendEvent ( new ThreadEvent ( "exited" , this . _connection . id ) ) ;
128- this . _connection . close ( ) ;
129- this . _connection = null ;
130- } ;
131- this . _connection = new xdebug . Connection ( socket )
132- . on ( "warning" , ( warning : string ) => {
133- this . sendEvent ( new OutputEvent ( warning + "\n" ) ) ;
134- } )
135- . on ( "close" , disposeConnection )
136- . on ( "stdout" , ( data : string ) => {
137- this . sendEvent ( new OutputEvent ( data , "stdout" ) ) ;
121+ await api . serverInfo ( ) ;
122+
123+ const socket = new WebSocket ( this . _url , {
124+ headers : {
125+ cookie : this . cookies ,
126+ } ,
138127 } ) ;
139128
140- try {
129+ const disposeConnection = ( error ?: Error ) : void => {
130+ this . sendEvent ( new ThreadEvent ( "exited" , this . _connection . id ) ) ;
131+ this . _connection . close ( ) ;
132+ this . _connection = null ;
133+ } ;
134+ this . _connection = new xdebug . Connection ( socket )
135+ . on ( "warning" , ( warning : string ) => {
136+ this . sendEvent ( new OutputEvent ( warning + "\n" ) ) ;
137+ } )
138+ . on ( "close" , disposeConnection )
139+ . on ( "stdout" , ( data : string ) => {
140+ this . sendEvent ( new OutputEvent ( data , "stdout" ) ) ;
141+ } ) ;
142+
141143 await this . _connection . waitForInitPacket ( ) ;
142144
143145 await this . _connection . sendFeatureSetCommand ( "max_data" , 8192 ) ;
@@ -326,26 +328,31 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
326328 const fileUri = DocumentContentProvider . getUri ( routine , null , namespace ) . toString ( ) ;
327329 const source = new Source ( routine , fileUri ) ;
328330 let line = stackFrame . line + 1 ;
329- if ( source . name . endsWith ( ".cls" ) && stackFrame . method !== "" ) {
330- line = await vscode . workspace . openTextDocument ( vscode . Uri . parse ( source . path ) ) . then ( ( document ) => {
331+ const place = `${ stackFrame . method } +${ stackFrame . methodOffset } ` ;
332+ const stackFrameId = this . _stackFrameIdCounter ++ ;
333+ let noSource = false ;
334+ try {
335+ const document = await vscode . workspace . openTextDocument ( vscode . Uri . parse ( source . path ) ) ;
336+ if ( source . name . endsWith ( ".cls" ) && stackFrame . method !== "" ) {
331337 const methodMatchPattern = new RegExp ( `^(Class)?Method ${ stackFrame . method } (?=[( ])` , "i" ) ;
332338 for ( let i = 0 ; i < document . lineCount ; i ++ ) {
333- const line = document . lineAt ( i ) ;
339+ const codeLine = document . lineAt ( i ) ;
334340
335- const methodMatch = line . text . match ( methodMatchPattern ) ;
341+ const methodMatch = codeLine . text . match ( methodMatchPattern ) ;
336342 if ( methodMatch ) {
337- return i + 2 + stackFrame . methodOffset ;
343+ line = i + 2 + stackFrame . methodOffset ;
344+ break ;
338345 }
339346 }
340- } ) ;
347+ }
348+ this . _stackFrames . set ( stackFrameId , stackFrame ) ;
349+ } catch ( ex ) {
350+ noSource = true ;
341351 }
342- const place = `${ stackFrame . method } +${ stackFrame . methodOffset } ` ;
343- const stackFrameId = this . _stackFrameIdCounter ++ ;
344- this . _stackFrames . set ( stackFrameId , stackFrame ) ;
345352 return {
346353 id : stackFrameId ,
347354 name : place ,
348- source,
355+ source : noSource ? null : source ,
349356 line,
350357 column : 1 ,
351358 } ;
0 commit comments