Skip to content

Commit 32a097e

Browse files
authored
Merge branch 'main' into feature/esbuild-sourcemaps
2 parents 75cd124 + bf54870 commit 32a097e

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"@typescript-eslint/eslint-plugin": "6.4.0",
9797
"@typescript-eslint/parser": "6.4.0",
9898
"@ungap/structured-clone": "1.2.0",
99+
"@vscode/debugprotocol": "1.61.0",
99100
"@vscode/test-electron": "2.3.4",
100101
"@vscode/vsce": "2.20.1",
101102
"esbuild": "0.19.2",

src/features/DebugSession.ts

+35-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
QuickPickOptions,
2525
DebugConfigurationProviderTriggerKind
2626
} from "vscode";
27+
import type { DebugProtocol } from "@vscode/debugprotocol";
2728
import { NotificationType, RequestType } from "vscode-languageclient";
2829
import { LanguageClient } from "vscode-languageclient/node";
2930
import { LanguageClientConsumer } from "../languageClientConsumer";
@@ -375,25 +376,48 @@ export class DebugSessionFeature extends LanguageClientConsumer
375376
dotnetAttachConfig.processId = pid;
376377

377378
// Ensure the .NET session stops before the PowerShell session so that the .NET debug session doesn't emit an error about the process unexpectedly terminating.
378-
const startDebugEvent = debug.onDidStartDebugSession((dotnetAttachSession) => {
379+
let tempConsoleDotnetAttachSession: DebugSession;
380+
const startDebugEvent = debug.onDidStartDebugSession(dotnetAttachSession => {
381+
if (dotnetAttachSession.configuration.name != dotnetAttachConfig.name) { return; }
382+
379383
// Makes the event one-time
380384
// HACK: This seems like you would be calling a method on a variable not assigned yet, but it does work in the flow.
381385
// 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
382386
startDebugEvent.dispose();
387+
383388
this.logger.writeVerbose(`Debugger session detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id})`);
384-
if (dotnetAttachSession.configuration.name == dotnetAttachConfig.name) {
385-
const stopDebugEvent = debug.onDidTerminateDebugSession(async (terminatedDebugSession) => {
386-
// Makes the event one-time
387-
stopDebugEvent.dispose();
388389

389-
this.logger.writeVerbose(`Debugger session stopped: ${terminatedDebugSession.name} (${terminatedDebugSession.id})`);
390+
tempConsoleDotnetAttachSession = dotnetAttachSession;
391+
392+
const stopDebugEvent = debug.onDidTerminateDebugSession(async tempConsoleSession => {
393+
if (tempConsoleDotnetAttachSession.parentSession?.id !== tempConsoleSession.id) { return; }
390394

391-
if (terminatedDebugSession === session) {
392-
this.logger.writeVerbose("Terminating dotnet debugger session associated with PowerShell debug session!");
393-
await debug.stopDebugging(dotnetAttachSession);
395+
// Makes the event one-time
396+
stopDebugEvent.dispose();
397+
398+
this.logger.writeVerbose(`Debugger session terminated: ${tempConsoleSession.name} (${tempConsoleSession.id})`);
399+
400+
// 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.
401+
const disconnectRequest: DebugProtocol.DisconnectRequest = {
402+
command: "disconnect",
403+
seq: 0,
404+
type: "request",
405+
arguments: {
406+
restart: false,
407+
terminateDebuggee: false,
408+
suspendDebuggee: false
394409
}
395-
});
396-
}
410+
};
411+
412+
try {
413+
await dotnetAttachSession.customRequest(
414+
disconnectRequest.command,
415+
disconnectRequest.arguments
416+
);
417+
} catch (err) {
418+
this.logger.writeWarning(`Disconnect request to dotnet debugger failed: ${err}`);
419+
}
420+
});
397421
});
398422

399423
// Start a child debug session to attach the dotnet debugger

test/features/DebugSession.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,16 @@ describe("DebugSessionFeature", () => {
428428
});
429429
});
430430

431-
describe("DebugSessionFeature E2E", () => {
431+
describe("DebugSessionFeature E2E", function() {
432+
// E2E tests can take a while to run since the debugger has to start up and attach
433+
this.slow(20000);
432434
before(async () => {
433435
// Registers and warms up the debug adapter and the PowerShell Extension Terminal
434436
await ensureEditorServicesIsConnected();
435437
});
436438

437439
it("Starts and stops a debugging session", async () => {
440+
438441
// Inspect the debug session via the started events to ensure it is correct
439442
const startDebugSession = new Promise<DebugSession>((resolve) => {
440443
const event = debug.onDidStartDebugSession((session) => {

test/features/ISECompatibility.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ describe("ISE compatibility feature", function () {
7373
});
7474

7575
describe("Color theme interactions", function () {
76+
// These tests are slow because they change the user's theme.
77+
this.slow(3000);
7678
beforeEach(enableISEMode);
7779

7880
function assertISESettings(): void {

0 commit comments

Comments
 (0)