Skip to content

Commit f25224e

Browse files
committed
Add temporaryIntegratedConsoleExeName setting to allow different PS for temp console.
1 parent d22bf3d commit f25224e

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

examples/.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
45
{
56
"type": "PowerShell",
67
"request": "launch",
@@ -54,6 +55,13 @@
5455
"name": "PowerShell Attach to Host Process",
5556
"processId": "${command:PickPSHostProcess}",
5657
"runspaceId": 1
58+
},
59+
{
60+
"name": "Windows PowerShell",
61+
"type": "PowerShell",
62+
"request": "launch",
63+
"cwd": "${workspaceRoot}",
64+
"temporaryIntegratedConsoleExeName": "Windows PowerShell (x64)"
5765
}
5866
]
5967
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@
556556
"description": "Determines whether a temporary PowerShell Extension Terminal is created for each debugging session, useful for debugging PowerShell classes and binary modules. Overrides the user setting 'powershell.debugging.createTemporaryIntegratedConsole'.",
557557
"default": false
558558
},
559+
"temporaryIntegratedConsoleExeName": {
560+
"type": "string",
561+
"description": "If specified, uses the powershell executable defined in the powerShellAdditionalExePaths setting to launch the temporary extension terminal. Implies createTemporaryIntegratedConsole",
562+
"default": null
563+
},
559564
"attachDotnetDebugger": {
560565
"type": "boolean",
561566
"description": "If specified, a C# debug session will be started and attached to the new temporary extension terminal. This does nothing unless 'powershell.debugging.createTemporaryIntegratedConsole' is also specified.",
@@ -1162,4 +1167,4 @@
11621167
]
11631168
},
11641169
"private": true
1165-
}
1170+
}

src/features/DebugSession.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ export class DebugSessionFeature
440440
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
441441
}
442442

443+
if (config.temporaryIntegratedConsoleExeName) {
444+
config.createTemporaryIntegratedConsole = true;
445+
}
446+
443447
if (config.attachDotnetDebugger) {
444448
return this.resolveAttachDotnetDebugConfiguration(config);
445449
}
@@ -477,7 +481,10 @@ export class DebugSessionFeature
477481
): Promise<IEditorServicesSessionDetails | undefined> {
478482
const settings = getSettings();
479483
this.tempDebugProcess =
480-
await this.sessionManager.createDebugSessionProcess(settings);
484+
await this.sessionManager.createDebugSessionProcess(
485+
settings,
486+
session.configuration.temporaryIntegratedConsoleExeName,
487+
);
481488
// TODO: Maybe set a timeout on the cancellation token?
482489
const cancellationTokenSource = new CancellationTokenSource();
483490
this.tempSessionDetails = await this.tempDebugProcess.start(

src/session.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export class SessionManager implements Middleware {
442442

443443
public async createDebugSessionProcess(
444444
settings: Settings,
445+
powershellExeName?: string,
445446
): Promise<PowerShellProcess> {
446447
// NOTE: We only support one temporary Extension Terminal at a time. To
447448
// support more, we need to track each separately, and tie the session
@@ -455,14 +456,20 @@ export class SessionManager implements Middleware {
455456
);
456457
}
457458

459+
const debugPowerShellExeDetails =
460+
powershellExeName === undefined
461+
? this.PowerShellExeDetails
462+
: ((await this.findPowerShell(powershellExeName)) ??
463+
this.PowerShellExeDetails);
464+
458465
// TODO: It might not be totally necessary to update the session
459466
// settings here, but I don't want to accidentally change this behavior
460467
// just yet. Working on getting things to be more idempotent!
461468
this.sessionSettings = settings;
462469

463470
const bundledModulesPath = await this.getBundledModulesPath();
464471
this.debugSessionProcess = new PowerShellProcess(
465-
this.PowerShellExeDetails.exePath,
472+
debugPowerShellExeDetails.exePath,
466473
bundledModulesPath,
467474
true,
468475
false,
@@ -716,7 +723,9 @@ export class SessionManager implements Middleware {
716723
];
717724
}
718725

719-
private async findPowerShell(): Promise<IPowerShellExeDetails | undefined> {
726+
private async findPowerShell(
727+
wantedName?: string,
728+
): Promise<IPowerShellExeDetails | undefined> {
720729
this.logger.writeDebug("Finding PowerShell...");
721730
const powershellExeFinder = new PowerShellExeFinder(
722731
this.platformDetails,
@@ -727,7 +736,7 @@ export class SessionManager implements Middleware {
727736
let foundPowerShell: IPowerShellExeDetails | undefined;
728737
try {
729738
let defaultPowerShell: IPowerShellExeDetails | undefined;
730-
const wantedName = this.sessionSettings.powerShellDefaultVersion;
739+
wantedName ??= this.sessionSettings.powerShellDefaultVersion;
731740
if (wantedName !== "") {
732741
for await (const details of powershellExeFinder.enumeratePowerShellInstallations()) {
733742
// Need to compare names case-insensitively, from https://stackoverflow.com/a/2140723

0 commit comments

Comments
 (0)