In Development mode, write the PID to a file where the parent session can find it, to attach the dotnet debugger.
(
pwshProcess: PowerShellProcess,
)
| 371 | |
| 372 | /** In Development mode, write the PID to a file where the parent session can find it, to attach the dotnet debugger. */ |
| 373 | private async writePidIfInDevMode( |
| 374 | pwshProcess: PowerShellProcess, |
| 375 | ): Promise<void> { |
| 376 | if ( |
| 377 | this.extensionContext.extensionMode !== |
| 378 | vscode.ExtensionMode.Development |
| 379 | ) { |
| 380 | return; |
| 381 | } |
| 382 | const parentSessionId = process.env.VSCODE_PARENT_SESSION_ID; |
| 383 | const pidFilePath = vscode.Uri.joinPath( |
| 384 | this.sessionsFolder, |
| 385 | `PSES-${parentSessionId}.pid`, |
| 386 | ); |
| 387 | |
| 388 | if (parentSessionId === undefined) { |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | const fs = vscode.workspace.fs; |
| 393 | const pid = (await pwshProcess.getPid())!.toString(); |
| 394 | await fs.writeFile(pidFilePath, Buffer.from(pid)); |
| 395 | const deletePidOnExit = pwshProcess.onExited(() => { |
| 396 | deletePidOnExit.dispose(); |
| 397 | fs.delete(pidFilePath, { useTrash: false }); |
| 398 | console.log(`Deleted PID file: ${pidFilePath}`); |
| 399 | }); |
| 400 | this.registeredCommands.push(deletePidOnExit); |
| 401 | this.extensionContext.subscriptions.push(deletePidOnExit); |
| 402 | } |
| 403 | |
| 404 | public getSessionDetails(): IEditorServicesSessionDetails | undefined { |
| 405 | // This is used by the debugger which should have already called `start`. |