Skip to content

Commit 037fb49

Browse files
committed
Add sessionName debugger option to specify the session name to use when debugging
Also adds sample profiles for Windows PowerShell
1 parent d22bf3d commit 037fb49

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@
529529
"createTemporaryIntegratedConsole": true,
530530
"attachDotnetDebugger": true
531531
}
532+
},
533+
{
534+
"label": "PowerShell: Windows PowerShell",
535+
"description": "(Windows Only) Launch a temporary Windows PowerShell console for debugging. This is useful for debugging legacy scripts that require Windows PowerShell.",
536+
"body": {
537+
"name": "PowerShell: Windows PowerShell",
538+
"type": "PowerShell",
539+
"request": "launch",
540+
"sessionName": "Windows PowerShell (x64)"
541+
}
532542
}
533543
],
534544
"configurationAttributes": {
@@ -556,6 +566,14 @@
556566
"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'.",
557567
"default": false
558568
},
569+
"sessionName": {
570+
"type": [
571+
"string",
572+
"null"
573+
],
574+
"description": "If specified, uses the PowerShell session name to launch the debug configuration. Will always launch in a temporary console if specified.",
575+
"default": null
576+
},
559577
"attachDotnetDebugger": {
560578
"type": "boolean",
561579
"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 +1180,4 @@
11621180
]
11631181
},
11641182
"private": true
1165-
}
1183+
}

src/features/DebugSession.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export enum DebugConfig {
5656
ModuleInteractiveSession,
5757
BinaryModule,
5858
BinaryModulePester,
59+
WindowsPowerShell,
5960
}
6061

6162
/** Make the implicit behavior of undefined and null in the debug api more explicit */
@@ -126,6 +127,12 @@ export const DebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
126127
createTemporaryIntegratedConsole: true,
127128
attachDotnetDebugger: true,
128129
},
130+
[DebugConfig.WindowsPowerShell]: {
131+
name: "PowerShell: Windows PowerShell",
132+
type: "PowerShell",
133+
request: "launch",
134+
temporaryIntegratedConsoleExeName: "Windows PowerShell (x64)",
135+
},
129136
};
130137

131138
export class DebugSessionFeature
@@ -440,6 +447,10 @@ export class DebugSessionFeature
440447
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
441448
}
442449

450+
if (config.sessionName) {
451+
config.createTemporaryIntegratedConsole = true;
452+
}
453+
443454
if (config.attachDotnetDebugger) {
444455
return this.resolveAttachDotnetDebugConfiguration(config);
445456
}
@@ -477,7 +488,10 @@ export class DebugSessionFeature
477488
): Promise<IEditorServicesSessionDetails | undefined> {
478489
const settings = getSettings();
479490
this.tempDebugProcess =
480-
await this.sessionManager.createDebugSessionProcess(settings);
491+
await this.sessionManager.createDebugSessionProcess(
492+
settings,
493+
session.configuration.sessionName,
494+
);
481495
// TODO: Maybe set a timeout on the cancellation token?
482496
const cancellationTokenSource = new CancellationTokenSource();
483497
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)