Skip to content

Commit 58aa029

Browse files
authored
Feature: Add sessionName debug setting to allow different PS for temp console (#5208)
* Add sessionName debug option to specify PowerShell Session for temporary console * Fix old name reference
1 parent d22bf3d commit 58aa029

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@
519519
}
520520
},
521521
{
522-
"label": "Run Pester Tests (Binary Module)",
522+
"label": "PowerShell: Run Pester Tests (Binary Module)",
523523
"description": "Debug a .NET binary or hybrid module by running Pester tests. Breakpoints you set in your .NET (C#/F#/VB/etc.) code will be hit upon command execution. You may want to add a compile or watch action as a pre-launch task to this configuration.",
524524
"body": {
525525
"name": "PowerShell: Binary Module Pester Tests",
@@ -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.",

src/features/DebugSession.ts

Lines changed: 27 additions & 2 deletions
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+
sessionName: "Windows PowerShell (x64)",
135+
},
129136
};
130137

131138
export class DebugSessionFeature
@@ -271,13 +278,24 @@ export class DebugSessionFeature
271278
"Debug a .NET binary or hybrid module loaded into a PowerShell session. Breakpoints you set in your .NET (C#/F#/VB/etc.) code will be hit upon command execution. You may want to add a compile or watch action as a pre-launch task to this configuration.",
272279
},
273280
{
274-
id: DebugConfig.RunPester,
281+
id: DebugConfig.BinaryModulePester,
275282
label: "Run Pester Tests (Binary Module)",
276283
description:
277284
"Debug a .NET binary or hybrid module by running Pester tests. Breakpoints you set in your .NET (C#/F#/VB/etc.) code will be hit upon command execution. You may want to add a compile or watch action as a pre-launch task to this configuration.",
278285
},
279286
];
280287

288+
// Only show the Windows PowerShell option if the platform is Windows
289+
const platformDetails = getPlatformDetails();
290+
if (platformDetails.operatingSystem === OperatingSystem.Windows) {
291+
debugConfigPickItems.push({
292+
id: DebugConfig.WindowsPowerShell,
293+
label: "Windows PowerShell",
294+
description:
295+
"Launch Windows PowerShell in a temporary integrated console for debugging",
296+
});
297+
}
298+
281299
const launchSelection = await window.showQuickPick(
282300
debugConfigPickItems,
283301
{ placeHolder: "Select a PowerShell debug configuration" },
@@ -440,6 +458,10 @@ export class DebugSessionFeature
440458
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
441459
}
442460

461+
if (config.sessionName) {
462+
config.createTemporaryIntegratedConsole = true;
463+
}
464+
443465
if (config.attachDotnetDebugger) {
444466
return this.resolveAttachDotnetDebugConfiguration(config);
445467
}
@@ -477,7 +499,10 @@ export class DebugSessionFeature
477499
): Promise<IEditorServicesSessionDetails | undefined> {
478500
const settings = getSettings();
479501
this.tempDebugProcess =
480-
await this.sessionManager.createDebugSessionProcess(settings);
502+
await this.sessionManager.createDebugSessionProcess(
503+
settings,
504+
session.configuration.sessionName,
505+
);
481506
// TODO: Maybe set a timeout on the cancellation token?
482507
const cancellationTokenSource = new CancellationTokenSource();
483508
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy