MCPcopy
hub / github.com/PowerShell/vscode-powershell / writePidIfInDevMode

Method writePidIfInDevMode

src/session.ts:373–402  ·  view source on GitHub ↗

In Development mode, write the PID to a file where the parent session can find it, to attach the dotnet debugger.

(
        pwshProcess: PowerShellProcess,
    )

Source from the content-addressed store, hash-verified

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`.

Callers 1

startMethod · 0.95

Calls 3

getPidMethod · 0.80
logMethod · 0.80
disposeMethod · 0.45

Tested by

no test coverage detected