Skip to content

Commit f3a44b8

Browse files
authored
Add new debug configurations to package.json (#4516)
* Add new Debug Configurations to package.json Also register debug session handler for both dynamic and initial * Fix test because we now register two providers
1 parent 1a217d7 commit f3a44b8

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,52 @@
501501
"request": "attach",
502502
"processId": "current"
503503
}
504+
},
505+
{
506+
"label": "PowerShell: Run Pester Tests",
507+
"description": "Debug Pester Tests detected in your current directory (runs Invoke-Pester)",
508+
"body": {
509+
"name": "PowerShell Run Pester Tests",
510+
"type": "PowerShell",
511+
"request": "launch",
512+
"script": "Invoke-Pester",
513+
"createTemporaryIntegratedConsole": true,
514+
"attachDotnetDebugger": true
515+
}
516+
},
517+
{
518+
"label": "PowerShell: Interactive Session (Module)",
519+
"description": "Debug commands executed from the PowerShell Extension Terminal after auto-loading your module",
520+
"body": {
521+
"name": "PowerShell: Module Interactive Session",
522+
"type": "PowerShell",
523+
"request": "launch",
524+
"script": "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\""
525+
}
526+
},
527+
{
528+
"label": "PowerShell: Interactive Session (Binary Module)",
529+
"description": "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.",
530+
"body": {
531+
"name": "PowerShell: Binary Module Interactive",
532+
"type": "PowerShell",
533+
"request": "launch",
534+
"script": "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\"",
535+
"createTemporaryIntegratedConsole": true,
536+
"attachDotnetDebugger": true
537+
}
538+
},
539+
{
540+
"label": "Run Pester Tests (Binary Module)",
541+
"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.",
542+
"body": {
543+
"name": "PowerShell: Binary Module Pester Tests",
544+
"type": "PowerShell",
545+
"request": "launch",
546+
"script": "Invoke-Pester",
547+
"createTemporaryIntegratedConsole": true,
548+
"attachDotnetDebugger": true
549+
}
504550
}
505551
],
506552
"configurationAttributes": {

src/features/DebugSession.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
CancellationTokenSource,
2222
InputBoxOptions,
2323
QuickPickItem,
24-
QuickPickOptions
24+
QuickPickOptions,
25+
DebugConfigurationProviderTriggerKind
2526
} from "vscode";
2627
import { NotificationType, RequestType } from "vscode-languageclient";
2728
import { LanguageClient } from "vscode-languageclient/node";
@@ -60,6 +61,7 @@ const PREVENT_DEBUG_START = undefined;
6061
const PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG = null;
6162

6263
/** Represents the various built-in debug configurations that will be advertised to the user if they choose "Add Config" from the launch debug config window */
64+
// NOTE: These are duplicated with what is in package.json until https://github.com/microsoft/vscode/issues/150663#issuecomment-1506134754 is resolved.
6365
export const defaultDebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
6466
[DebugConfig.LaunchCurrentFile]: {
6567
name: "PowerShell: Launch Current File",
@@ -129,7 +131,12 @@ export class DebugSessionFeature extends LanguageClientConsumer
129131
constructor(context: ExtensionContext, private sessionManager: SessionManager, private logger: ILogger) {
130132
super();
131133
// This "activates" the debug adapter for use with You can only do this once.
132-
context.subscriptions.push(debug.registerDebugConfigurationProvider("PowerShell", this));
134+
[
135+
DebugConfigurationProviderTriggerKind.Initial,
136+
DebugConfigurationProviderTriggerKind.Dynamic
137+
].forEach(triggerKind => {
138+
context.subscriptions.push(debug.registerDebugConfigurationProvider("PowerShell", this, triggerKind));
139+
});
133140
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory("PowerShell", this));
134141
}
135142

@@ -199,7 +206,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
199206
{
200207
id: DebugConfig.RunPester,
201208
label: "Run Pester Tests (Binary Module)",
202-
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.",
209+
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.",
203210
},
204211
];
205212

test/features/DebugSession.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ describe("DebugSessionFeature", () => {
6464
});
6565

6666
createDebugSessionFeatureStub({context: context});
67-
6867
assert.ok(registerFactoryStub.calledOnce, "Debug adapter factory method called");
69-
assert.ok(registerProviderStub.calledOnce, "Debug config provider method called");
70-
assert.equal(context.subscriptions.length, 2, "DebugSessionFeature disposables populated");
68+
assert.ok(registerProviderStub.calledTwice, "Debug config provider registered for both Initial and Dynamic");
69+
assert.equal(context.subscriptions.length, 3, "DebugSessionFeature disposables populated");
7170
// TODO: Validate the registration content, such as the language name
7271
});
7372
});

0 commit comments

Comments
 (0)