@@ -63,6 +63,15 @@ async function convertClientPathToDebugger(uri: vscode.Uri, namespace: string):
63
63
}
64
64
65
65
export class ObjectScriptDebugSession extends LoggingDebugSession {
66
+ /** After setupAPI() has been called this will return the serverId string */
67
+ public get serverId ( ) : string | undefined {
68
+ return this . _api ?. serverId ;
69
+ }
70
+
71
+ private _api ?: AtelierAPI ;
72
+
73
+ private _workspaceFolderUri ?: vscode . Uri ;
74
+
66
75
private _statuses = new Map < xdebug . Connection , xdebug . StatusResponse > ( ) ;
67
76
68
77
private _connection : xdebug . Connection ;
@@ -89,8 +98,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
89
98
90
99
private _workspace : string ;
91
100
92
- private cookies : string [ ] = [ ] ;
93
-
94
101
/** If this is a CSPDEBUG session */
95
102
private _isCsp = false ;
96
103
@@ -106,9 +113,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
106
113
/** If we're stopped at a breakpoint. */
107
114
private _break = false ;
108
115
109
- /** If we should automatically stop target */
110
- private _stopOnEntry : boolean ;
111
-
112
116
/** If this is a `launch` session */
113
117
private _isLaunch = false ;
114
118
@@ -127,6 +131,27 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
127
131
} while ( ! this . _debugTargetSet ) ;
128
132
}
129
133
134
+ /** To be called immediately after construction */
135
+ public setupAPI ( workspaceFolderUri ?: vscode . Uri ) : void {
136
+ // Only effective the first time
137
+ if ( this . _api ) {
138
+ return ;
139
+ }
140
+
141
+ this . _workspaceFolderUri = workspaceFolderUri ;
142
+ if ( workspaceFolderUri ) {
143
+ // The uri of the relevant workspace folder was set after construction
144
+ this . _workspace = undefined ;
145
+ this . _api = new AtelierAPI ( workspaceFolderUri ) ;
146
+ } else {
147
+ // Fall back to old way of deciding where to connect
148
+ const file = currentFile ( ) ;
149
+ this . _workspace = file ?. workspaceFolder ;
150
+ this . _api = new AtelierAPI ( file ?. uri ) ;
151
+ }
152
+ return ;
153
+ }
154
+
130
155
/** Check if the target is stopped */
131
156
private async _isStopped ( ) : Promise < boolean > {
132
157
return this . _connection
@@ -164,21 +189,16 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
164
189
} ;
165
190
166
191
try {
167
- const file = currentFile ( ) ;
168
- this . _workspace = file ?. workspaceFolder ;
169
-
170
- const api = new AtelierAPI ( file ?. uri ) ;
171
- this . cookies = api . cookies ;
172
- if ( ! api . active ) {
192
+ if ( ! this . _api . active ) {
173
193
throw new Error ( "Connection not active" ) ;
174
194
}
175
- this . _namespace = api . ns ;
176
- this . _url = api . xdebugUrl ( ) ;
195
+ this . _namespace = this . _api . ns ;
196
+ this . _url = this . _api . xdebugUrl ( ) ;
177
197
178
198
const socket = new WebSocket ( this . _url , {
179
199
rejectUnauthorized : vscode . workspace . getConfiguration ( "http" ) . get ( "proxyStrictSSL" ) ,
180
200
headers : {
181
- cookie : this . cookies ,
201
+ cookie : this . _api . cookies ,
182
202
} ,
183
203
} ) ;
184
204
@@ -228,7 +248,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
228
248
229
249
protected async launchRequest ( response : DebugProtocol . LaunchResponse , args : LaunchRequestArguments ) : Promise < void > {
230
250
try {
231
- this . _debugTargetSet = this . _stopOnEntry = false ;
251
+ this . _debugTargetSet = false ;
232
252
this . _isLaunch = true ;
233
253
const debugTarget = `${ this . _namespace } :${ args . program } ` ;
234
254
await this . _connection . sendFeatureSetCommand ( "debug_target" , debugTarget , true ) ;
@@ -243,8 +263,8 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
243
263
protected async attachRequest ( response : DebugProtocol . AttachResponse , args : AttachRequestArguments ) : Promise < void > {
244
264
try {
245
265
this . _debugTargetSet = this . _isLaunch = false ;
246
- this . _stopOnEntry = args . stopOnEntry ;
247
- const debugTarget = args . cspDebugId != undefined ? `CSPDEBUG:${ args . cspDebugId } ` : `PID:${ args . processId } ` ;
266
+ const debugTarget =
267
+ args . cspDebugId != undefined ? `CSPDEBUG:${ args . cspDebugId } ` : `PID:${ args . processId . split ( "@" ) [ 0 ] } ` ;
248
268
await this . _connection . sendFeatureSetCommand ( "debug_target" , debugTarget ) ;
249
269
if ( args . cspDebugId != undefined ) {
250
270
if ( args . isUnitTest ) {
@@ -258,7 +278,6 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
258
278
await this . _connection . sendBreakpointSetCommand ( new xdebug . Watchpoint ( "ok" , this . _cspWatchpointCondition ) ) ;
259
279
this . _isCsp = true ;
260
280
}
261
- this . _stopOnEntry = false ;
262
281
this . sendResponse ( response ) ;
263
282
} else {
264
283
this . _isCsp = false ;
@@ -291,11 +310,9 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
291
310
args : DebugProtocol . ConfigurationDoneArguments
292
311
) : Promise < void > {
293
312
if ( ! this . _isLaunch && ! this . _isCsp ) {
294
- // The debug agent ignores the first run command for non-CSP attaches,
295
- // so send one right away, regardless of the stopOnEntry value
313
+ // The debug agent ignores the first run command
314
+ // for non-CSP attaches, so send one right away
296
315
await this . _connection . sendRunCommand ( ) ;
297
- }
298
- if ( this . _stopOnEntry && ! this . _isLaunch && ! this . _isCsp ) {
299
316
// Tell VS Code that we're stopped
300
317
this . sendResponse ( response ) ;
301
318
const event : DebugProtocol . StoppedEvent = new StoppedEvent ( "entry" , this . _connection . id ) ;
@@ -597,7 +614,13 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
597
614
stack . stack . map ( async ( stackFrame : xdebug . StackFrame , index ) : Promise < StackFrame > => {
598
615
const [ , namespace , name ] = decodeURI ( stackFrame . fileUri ) . match ( / ^ d b g p : \/ \/ \| ( [ ^ | ] + ) \| ( .* ) $ / ) ;
599
616
const routine = name ;
600
- const fileUri = DocumentContentProvider . getUri ( routine , this . _workspace , namespace ) ;
617
+ const fileUri = DocumentContentProvider . getUri (
618
+ routine ,
619
+ this . _workspace ,
620
+ namespace ,
621
+ undefined ,
622
+ this . _workspaceFolderUri
623
+ ) ;
601
624
const source = new Source ( routine , fileUri . toString ( ) ) ;
602
625
let line = stackFrame . line + 1 ;
603
626
const place = `${ stackFrame . method } +${ stackFrame . methodOffset } ` ;
0 commit comments