Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d71946

Browse files
fflatenJustinGrote
andauthored
Fix: getDotnetNamedConfigOrDefault does not resolve correctly (#4517)
Fixes dotnetDebuggerConfigName-option in launch config when using new attachDotnetDebugger feature introduced in #3903. Always threw config not found-error when dotnetDebuggerConfigName was set. Co-authored-by: Justin Grote <JustinGrote@users.noreply.github.com>
1 parent f3a44b8 commit 4d71946

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

‎src/features/DebugSession.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ export class DebugSessionFeature extends LanguageClientConsumer
411411

412412
private getDotnetNamedConfigOrDefault(configName?: string): ResolveDebugConfigurationResult {
413413
if (configName) {
414-
const debugConfigs = workspace.getConfiguration("launch").get<DebugConfiguration[]>("configurations")??[];
415-
return debugConfigs.find(({ type, request, name, dotnetDebuggerConfigName }) =>
414+
const debugConfigs = this.getLaunchConfigurations();
415+
return debugConfigs.find(({ type, request, name }) =>
416416
type === "coreclr" &&
417417
request === "attach" &&
418-
name === dotnetDebuggerConfigName
418+
name === configName
419419
);
420420
}
421421

@@ -432,6 +432,11 @@ export class DebugSessionFeature extends LanguageClientConsumer
432432
};
433433
}
434434

435+
/** Fetches all available vscode launch configurations. This is abstracted out for easier testing */
436+
private getLaunchConfigurations(): DebugConfiguration[] {
437+
return workspace.getConfiguration("launch").get<DebugConfiguration[]>("configurations") ?? [];
438+
}
439+
435440
private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise<ResolveDebugConfigurationResult> {
436441
const platformDetails = getPlatformDetails();
437442
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
@@ -749,3 +754,4 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
749754
this.waitingForClientToken = undefined;
750755
}
751756
}
757+

‎test/features/DebugSession.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,56 @@ describe("DebugSessionFeature", () => {
352352
assert.equal(actual!, null);
353353
assert.match(logger.writeAndShowError.firstCall.args[0], /matchinglaunchconfigwasnotfound/);
354354
});
355+
356+
it("Finds the correct dotnetDebuggerConfigName", async () => {
357+
const foundDotnetConfig: DebugConfiguration = {
358+
name: "TestDotnetAttachConfig",
359+
request: "attach",
360+
type: "coreclr",
361+
};
362+
const candidateDotnetConfigs: DebugConfiguration[] = [
363+
{
364+
name: "BadCandidate1",
365+
type: "powershell",
366+
request: "attach"
367+
},
368+
{
369+
name: "BadCandidate2",
370+
type: "coreclr",
371+
request: "attach"
372+
},
373+
{ // This one has launch instead of attach and even tho it has same name, should not be matched
374+
name: foundDotnetConfig.name,
375+
type: "coreclr",
376+
request: "launch"
377+
},
378+
foundDotnetConfig, //This is the one we want to match
379+
{
380+
name: foundDotnetConfig.name,
381+
type: "notcoreclrExactly",
382+
request: "attach"
383+
},
384+
{
385+
name: `${foundDotnetConfig.name}notexactlythisname`,
386+
type: "coreclr",
387+
request: "attach"
388+
}
389+
];
390+
const attachConfig = defaultDebugConfig;
391+
attachConfig.script = "test.ps1"; // This bypasses the ${file} logic
392+
attachConfig.createTemporaryIntegratedConsole = true;
393+
attachConfig.attachDotnetDebugger = true;
394+
attachConfig.dotnetDebuggerConfigName = foundDotnetConfig.name;
395+
const debugSessionFeature = createDebugSessionFeatureStub({});
396+
397+
// The any is necessary to stub a private method
398+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
399+
Sinon.stub(debugSessionFeature, "getLaunchConfigurations" as any).returns(candidateDotnetConfigs);
400+
401+
const config = await debugSessionFeature.resolveDebugConfigurationWithSubstitutedVariables(undefined, attachConfig);
402+
403+
assert.deepStrictEqual(config!.dotnetAttachConfig, foundDotnetConfig);
404+
});
355405
});
356406

357407
describe("createDebugAdapterDescriptor", () => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /