diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 792d92ebed..0bd267d281 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -404,11 +404,11 @@ export class DebugSessionFeature extends LanguageClientConsumer private getDotnetNamedConfigOrDefault(configName?: string): ResolveDebugConfigurationResult { if (configName) { - const debugConfigs = workspace.getConfiguration("launch").get("configurations") ?? []; - return debugConfigs.find(({ type, request, name, dotnetDebuggerConfigName }) => + const debugConfigs = this.getLaunchConfigurations(); + return debugConfigs.find(({ type, request, name }) => type === "coreclr" && request === "attach" && - name === dotnetDebuggerConfigName + name === configName ); } @@ -425,6 +425,11 @@ export class DebugSessionFeature extends LanguageClientConsumer }; } + /** Fetches all available vscode launch configurations. This is abstracted out for easier testing */ + private getLaunchConfigurations(): DebugConfiguration[] { + return workspace.getConfiguration("launch").get("configurations") ?? []; + } + private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise { const platformDetails = getPlatformDetails(); const versionDetails = this.sessionManager.getPowerShellVersionDetails(); @@ -742,3 +747,4 @@ export class PickRunspaceFeature extends LanguageClientConsumer { this.waitingForClientToken = undefined; } } + diff --git a/test/features/DebugSession.test.ts b/test/features/DebugSession.test.ts index 191eafa336..d3f1ebc7ba 100644 --- a/test/features/DebugSession.test.ts +++ b/test/features/DebugSession.test.ts @@ -353,6 +353,56 @@ describe("DebugSessionFeature", () => { assert.equal(actual!, null); assert.match(logger.writeAndShowError.firstCall.args[0], /matching launch config was not found/); }); + + it("Finds the correct dotnetDebuggerConfigName", async () => { + const foundDotnetConfig: DebugConfiguration = { + name: "TestDotnetAttachConfig", + request: "attach", + type: "coreclr", + }; + const candidateDotnetConfigs: DebugConfiguration[] = [ + { + name: "BadCandidate1", + type: "powershell", + request: "attach" + }, + { + name: "BadCandidate2", + type: "coreclr", + request: "attach" + }, + { // This one has launch instead of attach and even tho it has same name, should not be matched + name: foundDotnetConfig.name, + type: "coreclr", + request: "launch" + }, + foundDotnetConfig, //This is the one we want to match + { + name: foundDotnetConfig.name, + type: "notcoreclrExactly", + request: "attach" + }, + { + name: `${foundDotnetConfig.name}notexactlythisname`, + type: "coreclr", + request: "attach" + } + ]; + const attachConfig = defaultDebugConfig; + attachConfig.script = "test.ps1"; // This bypasses the ${file} logic + attachConfig.createTemporaryIntegratedConsole = true; + attachConfig.attachDotnetDebugger = true; + attachConfig.dotnetDebuggerConfigName = foundDotnetConfig.name; + const debugSessionFeature = createDebugSessionFeatureStub({}); + + // The any is necessary to stub a private method + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Sinon.stub(debugSessionFeature, "getLaunchConfigurations" as any).returns(candidateDotnetConfigs); + + const config = await debugSessionFeature.resolveDebugConfigurationWithSubstitutedVariables(undefined, attachConfig); + + assert.deepStrictEqual(config!.dotnetAttachConfig, foundDotnetConfig); + }); }); describe("createDebugAdapterDescriptor", () => {