@@ -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
@@ -124,6 +131,27 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
124
131
} while ( ! this . _debugTargetSet ) ;
125
132
}
126
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
+
127
155
/** Check if the target is stopped */
128
156
private async _isStopped ( ) : Promise < boolean > {
129
157
return this . _connection
@@ -161,21 +189,16 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
161
189
} ;
162
190
163
191
try {
164
- const file = currentFile ( ) ;
165
- this . _workspace = file ?. workspaceFolder ;
166
-
167
- const api = new AtelierAPI ( file ?. uri ) ;
168
- this . cookies = api . cookies ;
169
- if ( ! api . active ) {
192
+ if ( ! this . _api . active ) {
170
193
throw new Error ( "Connection not active" ) ;
171
194
}
172
- this . _namespace = api . ns ;
173
- this . _url = api . xdebugUrl ( ) ;
195
+ this . _namespace = this . _api . ns ;
196
+ this . _url = this . _api . xdebugUrl ( ) ;
174
197
175
198
const socket = new WebSocket ( this . _url , {
176
199
rejectUnauthorized : vscode . workspace . getConfiguration ( "http" ) . get ( "proxyStrictSSL" ) ,
177
200
headers : {
178
- cookie : this . cookies ,
201
+ cookie : this . _api . cookies ,
179
202
} ,
180
203
} ) ;
181
204
@@ -240,7 +263,8 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
240
263
protected async attachRequest ( response : DebugProtocol . AttachResponse , args : AttachRequestArguments ) : Promise < void > {
241
264
try {
242
265
this . _debugTargetSet = this . _isLaunch = false ;
243
- 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 ] } ` ;
244
268
await this . _connection . sendFeatureSetCommand ( "debug_target" , debugTarget ) ;
245
269
if ( args . cspDebugId != undefined ) {
246
270
if ( args . isUnitTest ) {
@@ -590,7 +614,13 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
590
614
stack . stack . map ( async ( stackFrame : xdebug . StackFrame , index ) : Promise < StackFrame > => {
591
615
const [ , namespace , name ] = decodeURI ( stackFrame . fileUri ) . match ( / ^ d b g p : \/ \/ \| ( [ ^ | ] + ) \| ( .* ) $ / ) ;
592
616
const routine = name ;
593
- 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
+ ) ;
594
624
const source = new Source ( routine , fileUri . toString ( ) ) ;
595
625
let line = stackFrame . line + 1 ;
596
626
const place = `${ stackFrame . method } +${ stackFrame . methodOffset } ` ;
0 commit comments