Skip to content

Fix attachDotnetDebugger with custom config #4517

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 3 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
12 changes: 9 additions & 3 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ export class DebugSessionFeature extends LanguageClientConsumer

private getDotnetNamedConfigOrDefault(configName?: string): ResolveDebugConfigurationResult {
if (configName) {
const debugConfigs = workspace.getConfiguration("launch").get<DebugConfiguration[]>("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
);
}

Expand All @@ -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<DebugConfiguration[]>("configurations") ?? [];
}

private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise<ResolveDebugConfigurationResult> {
const platformDetails = getPlatformDetails();
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
Expand Down Expand Up @@ -742,3 +747,4 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
this.waitingForClientToken = undefined;
}
}

50 changes: 50 additions & 0 deletions test/features/DebugSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down