From 5d071db24a4608d267def7ba24f8c51986de0bc4 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Thu, 13 Apr 2023 20:40:58 +0000 Subject: [PATCH 1/3] Fix attachDotnetDebugger with custom dotnet config --- src/features/DebugSession.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 792d92ebed..e1d07719c7 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -405,10 +405,10 @@ 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 }) => + return debugConfigs.find(({ type, request, name }) => type === "coreclr" && request === "attach" && - name === dotnetDebuggerConfigName + name === configName ); } From 8c4cbdfce06914084694333db11a29594e878f72 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 14 Apr 2023 09:14:09 -0700 Subject: [PATCH 2/3] Add matching test --- src/features/DebugSession.ts | 8 ++++- test/features/DebugSession.test.ts | 50 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index e1d07719c7..0bd267d281 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -404,7 +404,7 @@ export class DebugSessionFeature extends LanguageClientConsumer private getDotnetNamedConfigOrDefault(configName?: string): ResolveDebugConfigurationResult { if (configName) { - const debugConfigs = workspace.getConfiguration("launch").get("configurations") ?? []; + const debugConfigs = this.getLaunchConfigurations(); return debugConfigs.find(({ type, request, name }) => type === "coreclr" && request === "attach" && @@ -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..15a22c9e51 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.only("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", () => { From aa04357b8dfa7dfd4e3cd0f5041b3383bc6467ff Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 14 Apr 2023 09:23:08 -0700 Subject: [PATCH 3/3] Remove Only (again) --- test/features/DebugSession.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/features/DebugSession.test.ts b/test/features/DebugSession.test.ts index 15a22c9e51..d3f1ebc7ba 100644 --- a/test/features/DebugSession.test.ts +++ b/test/features/DebugSession.test.ts @@ -354,7 +354,7 @@ describe("DebugSessionFeature", () => { assert.match(logger.writeAndShowError.firstCall.args[0], /matching launch config was not found/); }); - it.only("Finds the correct dotnetDebuggerConfigName", async () => { + it("Finds the correct dotnetDebuggerConfigName", async () => { const foundDotnetConfig: DebugConfiguration = { name: "TestDotnetAttachConfig", request: "attach",