Skip to content

Add new debug configurations to package.json #4516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,52 @@
"request": "attach",
"processId": "current"
}
},
{
"label": "PowerShell: Run Pester Tests",
"description": "Debug Pester Tests detected in your current directory (runs Invoke-Pester)",
"body": {
"name": "PowerShell Run Pester Tests",
"type": "PowerShell",
"request": "launch",
"script": "Invoke-Pester",
"createTemporaryIntegratedConsole": true,
"attachDotnetDebugger": true
}
},
{
"label": "PowerShell: Interactive Session (Module)",
"description": "Debug commands executed from the PowerShell Extension Terminal after auto-loading your module",
"body": {
"name": "PowerShell: Module Interactive Session",
"type": "PowerShell",
"request": "launch",
"script": "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\""
}
},
{
"label": "PowerShell: Interactive Session (Binary Module)",
"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.",
"body": {
"name": "PowerShell: Binary Module Interactive",
"type": "PowerShell",
"request": "launch",
"script": "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\"",
"createTemporaryIntegratedConsole": true,
"attachDotnetDebugger": true
}
},
{
"label": "Run Pester Tests (Binary Module)",
"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.",
"body": {
"name": "PowerShell: Binary Module Pester Tests",
"type": "PowerShell",
"request": "launch",
"script": "Invoke-Pester",
"createTemporaryIntegratedConsole": true,
"attachDotnetDebugger": true
}
}
],
"configurationAttributes": {
Expand Down
13 changes: 10 additions & 3 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
CancellationTokenSource,
InputBoxOptions,
QuickPickItem,
QuickPickOptions
QuickPickOptions,
DebugConfigurationProviderTriggerKind
} from "vscode";
import { NotificationType, RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
Expand Down Expand Up @@ -60,6 +61,7 @@ const PREVENT_DEBUG_START = undefined;
const PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG = null;

/** 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 */
// NOTE: These are duplicated with what is in package.json until https://github.com/microsoft/vscode/issues/150663#issuecomment-1506134754 is resolved.
export const defaultDebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
[DebugConfig.LaunchCurrentFile]: {
name: "PowerShell: Launch Current File",
Expand Down Expand Up @@ -129,7 +131,12 @@ export class DebugSessionFeature extends LanguageClientConsumer
constructor(context: ExtensionContext, private sessionManager: SessionManager, private logger: ILogger) {
super();
// This "activates" the debug adapter for use with You can only do this once.
context.subscriptions.push(debug.registerDebugConfigurationProvider("PowerShell", this));
[
DebugConfigurationProviderTriggerKind.Initial,
DebugConfigurationProviderTriggerKind.Dynamic
].forEach(triggerKind => {
context.subscriptions.push(debug.registerDebugConfigurationProvider("PowerShell", this, triggerKind));
});
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory("PowerShell", this));
}

Expand Down Expand Up @@ -199,7 +206,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
{
id: DebugConfig.RunPester,
label: "Run Pester Tests (Binary Module)",
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.",
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.",
},
];

Expand Down
5 changes: 2 additions & 3 deletions test/features/DebugSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ describe("DebugSessionFeature", () => {
});

createDebugSessionFeatureStub({context: context});

assert.ok(registerFactoryStub.calledOnce, "Debug adapter factory method called");
assert.ok(registerProviderStub.calledOnce, "Debug config provider method called");
assert.equal(context.subscriptions.length, 2, "DebugSessionFeature disposables populated");
assert.ok(registerProviderStub.calledTwice, "Debug config provider registered for both Initial and Dynamic");
assert.equal(context.subscriptions.length, 3, "DebugSessionFeature disposables populated");
// TODO: Validate the registration content, such as the language name
});
});
Expand Down