@@ -90,14 +90,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
90
90
public constructor ( ) {
91
91
super ( ) ;
92
92
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
-
101
93
// this debugger uses zero-based lines and columns
102
94
this . setDebuggerLinesStartAt1 ( false ) ;
103
95
this . setDebuggerColumnsStartAt1 ( false ) ;
@@ -117,27 +109,37 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
117
109
supportsStepBack : false ,
118
110
} ;
119
111
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 ( ) ;
125
120
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
+ } ,
138
127
} ) ;
139
128
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
+
141
143
await this . _connection . waitForInitPacket ( ) ;
142
144
143
145
await this . _connection . sendFeatureSetCommand ( "max_data" , 8192 ) ;
@@ -326,26 +328,31 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
326
328
const fileUri = DocumentContentProvider . getUri ( routine , null , namespace ) . toString ( ) ;
327
329
const source = new Source ( routine , fileUri ) ;
328
330
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 !== "" ) {
331
337
const methodMatchPattern = new RegExp ( `^(Class)?Method ${ stackFrame . method } (?=[( ])` , "i" ) ;
332
338
for ( let i = 0 ; i < document . lineCount ; i ++ ) {
333
- const line = document . lineAt ( i ) ;
339
+ const codeLine = document . lineAt ( i ) ;
334
340
335
- const methodMatch = line . text . match ( methodMatchPattern ) ;
341
+ const methodMatch = codeLine . text . match ( methodMatchPattern ) ;
336
342
if ( methodMatch ) {
337
- return i + 2 + stackFrame . methodOffset ;
343
+ line = i + 2 + stackFrame . methodOffset ;
344
+ break ;
338
345
}
339
346
}
340
- } ) ;
347
+ }
348
+ this . _stackFrames . set ( stackFrameId , stackFrame ) ;
349
+ } catch ( ex ) {
350
+ noSource = true ;
341
351
}
342
- const place = `${ stackFrame . method } +${ stackFrame . methodOffset } ` ;
343
- const stackFrameId = this . _stackFrameIdCounter ++ ;
344
- this . _stackFrames . set ( stackFrameId , stackFrame ) ;
345
352
return {
346
353
id : stackFrameId ,
347
354
name : place ,
348
- source,
355
+ source : noSource ? null : source ,
349
356
line,
350
357
column : 1 ,
351
358
} ;
0 commit comments