Skip to content

Commit a9a38a8

Browse files
committed
First attempt, customRequest references the wrong this
1 parent 566c8b2 commit a9a38a8

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/features/DebugSession.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,29 @@ export class DebugSessionFeature extends LanguageClientConsumer
381381
// The dispose shorthand demonry for making an event one-time courtesy of: https://github.com/OmniSharp/omnisharp-vscode/blob/b8b07bb12557b4400198895f82a94895cb90c461/test/integrationTests/launchConfiguration.integration.test.ts#L41-L45
382382
startDebugEvent.dispose();
383383
this.logger.writeVerbose(`Debugger session detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id})`);
384+
385+
// HACK: As of 2023-08-17, there is no vscode debug API to request the C# debugger to detach, so we send it a custom DAP request instead.
384386
if (dotnetAttachSession.configuration.name == dotnetAttachConfig.name) {
385-
const stopDebugEvent = debug.onDidTerminateDebugSession(async (terminatedDebugSession) => {
386-
// Makes the event one-time
387-
stopDebugEvent.dispose();
387+
const onTerminateAttachSession = debug.onDidTerminateDebugSession(async parentSession => {
388+
// HACK: Force the "this" on this since we are supplying a "this" to the function via an argument. There probably is a type-safe way to do this, but because we also need a self-reference to the function in order to make it a one-time action, I'm not sure how to do it.
389+
const dotnetAttachSession = this as unknown as DebugSession;
388390

389-
this.logger.writeVerbose(`Debugger session stopped: ${terminatedDebugSession.name} (${terminatedDebugSession.id})`);
391+
if (parentSession.parentSession?.id !== dotnetAttachSession.id) {return;}
390392

391-
if (terminatedDebugSession === session) {
392-
this.logger.writeVerbose("Terminating dotnet debugger session associated with PowerShell debug session!");
393-
await debug.stopDebugging(dotnetAttachSession);
394-
}
395-
});
396-
}
397-
});
393+
this.logger.writeVerbose(`Powershell Binary Debug Session Stop Detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id}), detaching dotnet debugger.`);
394+
395+
await dotnetAttachSession.customRequest(
396+
"disconnect",
397+
{
398+
restart: false,
399+
terminateDebuggee: false,
400+
suspendDebuggee: false
401+
}
402+
);
403+
404+
onTerminateAttachSession.dispose();
405+
}, session);
406+
}});
398407

399408
// Start a child debug session to attach the dotnet debugger
400409
// TODO: Accommodate multi-folder workspaces if the C# code is in a different workspace folder

0 commit comments

Comments
 (0)