Skip to content

Commit 495e971

Browse files
committed
Use named debug configurations instead of duplicating them
Now that we have a record of debug configurations we can fix these TODOs. Also fix name of the `DebugConfiguration` const export.
1 parent 14961fa commit 495e971

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

src/features/DebugSession.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG = null;
6262

6363
/** 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 */
6464
// NOTE: These are duplicated with what is in package.json until https://github.com/microsoft/vscode/issues/150663#issuecomment-1506134754 is resolved.
65-
export const defaultDebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
65+
export const DebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
6666
[DebugConfig.LaunchCurrentFile]: {
6767
name: "PowerShell: Launch Current File",
6868
type: "PowerShell",
@@ -150,12 +150,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
150150
this.handlers = [
151151
languageClient.onNotification(
152152
StartDebuggerNotificationType,
153-
// TODO: Use a named debug configuration.
154-
() => void debug.startDebugging(undefined, {
155-
request: "launch",
156-
type: "PowerShell",
157-
name: "PowerShell: Interactive Session"
158-
})),
153+
() => void debug.startDebugging(undefined, DebugConfigurations[DebugConfig.InteractiveSession])),
159154

160155
languageClient.onNotification(
161156
StopDebuggerNotificationType,
@@ -216,10 +211,10 @@ export class DebugSessionFeature extends LanguageClientConsumer
216211
{ placeHolder: "Select a PowerShell debug configuration" });
217212

218213
if (launchSelection) {
219-
return [defaultDebugConfigurations[launchSelection.id]];
214+
return [DebugConfigurations[launchSelection.id]];
220215
}
221216

222-
return [defaultDebugConfigurations[DebugConfig.LaunchCurrentFile]];
217+
return [DebugConfigurations[DebugConfig.LaunchCurrentFile]];
223218
}
224219

225220
// We don't use await here but we are returning a promise and the return syntax is easier in an async function
@@ -234,7 +229,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
234229
if (!config.request) {
235230
// No launch.json, create the default configuration for both unsaved
236231
// (Untitled) and saved documents.
237-
const LaunchCurrentFileConfig = defaultDebugConfigurations[DebugConfig.LaunchCurrentFile];
232+
const LaunchCurrentFileConfig = DebugConfigurations[DebugConfig.LaunchCurrentFile];
238233
config = { ...config, ...LaunchCurrentFileConfig };
239234
config.current_document = true;
240235
}
@@ -401,7 +396,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
401396
});
402397

403398
// Start a child debug session to attach the dotnet debugger
404-
// TODO: Accomodate multi-folder workspaces if the C# code is in a different workspace folder
399+
// TODO: Accommodate multi-folder workspaces if the C# code is in a different workspace folder
405400
await debug.startDebugging(undefined, dotnetAttachConfig, session);
406401
this.logger.writeVerbose(`Dotnet Attach Debug configuration: ${JSON.stringify(dotnetAttachConfig)}`);
407402
this.logger.write(`Attached dotnet debugger to process ${pid}`);
@@ -754,4 +749,3 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
754749
this.waitingForClientToken = undefined;
755750
}
756751
}
757-

src/features/ExtensionCommands.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LanguageClient } from "vscode-languageclient/node";
1212
import { ILogger } from "../logging";
1313
import { getSettings, validateCwdSetting } from "../settings";
1414
import { LanguageClientConsumer } from "../languageClientConsumer";
15+
import { DebugConfig, DebugConfigurations } from "./DebugSession";
1516

1617
export interface IExtensionCommand {
1718
name: string;
@@ -187,13 +188,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
187188

188189
vscode.commands.registerCommand("PowerShell.Debug.Start",
189190
async () => {
190-
// TODO: Use a named debug configuration.
191-
await vscode.debug.startDebugging(undefined, {
192-
name: "PowerShell: Launch Current File",
193-
type: "PowerShell",
194-
request: "launch",
195-
script: "${file}",
196-
});
191+
await vscode.debug.startDebugging(undefined, DebugConfigurations[DebugConfig.LaunchCurrentFile]);
197192
})
198193
];
199194
}

src/features/ISECompatibility.ts

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class ISECompatibilityFeature implements vscode.Disposable {
3232
private _originalSettings: Record<string, boolean | string | undefined> = {};
3333

3434
constructor() {
35-
// TODO: This test isn't great.
3635
const testSetting = ISECompatibilityFeature.settings[ISECompatibilityFeature.settings.length - 1];
3736
this._iseModeEnabled = vscode.workspace.getConfiguration(testSetting.path).get(testSetting.name) === testSetting.value;
3837
this._commandRegistrations = [

test/features/DebugSession.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import * as assert from "assert";
66
import Sinon from "sinon";
77
import { DebugAdapterNamedPipeServer, DebugConfiguration, DebugSession, Extension, ExtensionContext, Range, SourceBreakpoint, TextDocument, TextEditor, Uri, commands, debug, extensions, window, workspace } from "vscode";
88
import { Disposable } from "vscode-languageserver-protocol";
9-
import { DebugConfig, DebugSessionFeature, defaultDebugConfigurations } from "../../src/features/DebugSession";
9+
import { DebugConfig, DebugSessionFeature, DebugConfigurations } from "../../src/features/DebugSession";
1010
import { IPowerShellExtensionClient } from "../../src/features/ExternalApi";
1111
import * as platform from "../../src/platform";
1212
import { IPlatformDetails } from "../../src/platform";
1313
import { IEditorServicesSessionDetails, IPowerShellVersionDetails, SessionManager, SessionStatus } from "../../src/session";
1414
import * as utils from "../../src/utils";
1515
import { BuildBinaryModuleMock, WaitEvent, ensureEditorServicesIsConnected, stubInterface, testLogger } from "../utils";
1616

17-
const TEST_NUMBER = 7357; //7357 = TEST. Get it? :)
17+
const TEST_NUMBER = 7357; // 7357 = TEST. Get it? :)
1818

1919
let defaultDebugConfig: DebugConfiguration;
2020
beforeEach(() => {
2121
// This prevents state from creeping into the template between test runs
22-
defaultDebugConfig = structuredClone(defaultDebugConfigurations[DebugConfig.LaunchCurrentFile]);
22+
defaultDebugConfig = structuredClone(DebugConfigurations[DebugConfig.LaunchCurrentFile]);
2323
});
2424

2525
describe("DebugSessionFeature", () => {
@@ -81,7 +81,7 @@ describe("DebugSessionFeature", () => {
8181
const actual = await createDebugSessionFeatureStub({}).resolveDebugConfiguration(undefined, noRequestConfig);
8282

8383
assert.equal(actual!.current_document, true);
84-
assert.equal(actual!.request, defaultDebugConfigurations[DebugConfig.LaunchCurrentFile].request);
84+
assert.equal(actual!.request, DebugConfigurations[DebugConfig.LaunchCurrentFile].request);
8585
});
8686

8787
it("Errors if current file config was specified but no file is open in the editor", async () => {
@@ -450,7 +450,7 @@ describe("DebugSessionFeature E2E", () => {
450450
});
451451
});
452452

453-
const config = defaultDebugConfigurations[DebugConfig.InteractiveSession];
453+
const config = DebugConfigurations[DebugConfig.InteractiveSession];
454454
assert.ok(await debug.startDebugging(undefined, config), "Debug session should start");
455455
assert.equal((await startDebugSession).name, config.name, "Debug session name should match when started");
456456

@@ -482,7 +482,7 @@ describe("DebugSessionFeature E2E", () => {
482482
});
483483

484484
it("Debugs a binary module script", async () => {
485-
const launchScriptConfig = structuredClone(defaultDebugConfigurations[DebugConfig.LaunchScript]);
485+
const launchScriptConfig = structuredClone(DebugConfigurations[DebugConfig.LaunchScript]);
486486
launchScriptConfig.script = Uri.joinPath(binaryModulePath, "BinaryModuleTest.ps1").fsPath;
487487
launchScriptConfig.attachDotnetDebugger = true;
488488
launchScriptConfig.createTemporaryIntegratedConsole = true;
@@ -504,7 +504,7 @@ describe("DebugSessionFeature E2E", () => {
504504
});
505505

506506
it("Stops at a binary module breakpoint", async () => {
507-
const launchScriptConfig = structuredClone(defaultDebugConfigurations[DebugConfig.LaunchCurrentFile]);
507+
const launchScriptConfig = structuredClone(DebugConfigurations[DebugConfig.LaunchCurrentFile]);
508508
launchScriptConfig.attachDotnetDebugger = true;
509509
launchScriptConfig.createTemporaryIntegratedConsole = true;
510510
const testScriptPath = Uri.joinPath(binaryModulePath, "BinaryModuleTest.ps1");

0 commit comments

Comments
 (0)