fix(debugger): enable Stop for the selected debug session only (#4785)

Stop in the Debug tool window was enabled whenever any session was live, so a finished session's tab showed an active Stop that did nothing. It now follows the selected tab like Rerun, Resume, Pause and the step buttons; with no tab selected it still acts on any live session.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-20 18:34:04 +08:00
1 джерело 9c12cacbdb
коміт 4ce05ff14e
3 files changed
+38 -3

No files matched your search

+26 -1
Переглянути файл
@@ -10,7 +10,15 @@ import {
updateBreakpoint,
useBreakpoints,
} from "../breakpoints/store";
import { adoptSession, useExecutionPoint, useDebug, handleDebugEvent, type DebugSession } from "../state";
import {
adoptSession,
selectSession,
stopTarget,
useExecutionPoint,
useDebug,
handleDebugEvent,
type DebugSession,
} from "../state";
import { getContext } from "@/platform/context";
import styles from "../editor/editor.module.css";
@@ -314,6 +322,23 @@ describe("session events", () => {
expect(getContext().debugSessionActive).toBe(false);
});
it("enables Stop for the selected session tab only (#4738)", () => {
adoptSession(80, { name: "server" });
adoptSession(81, { name: "client" });
selectSession(80);
expect(getContext().debugCanStop).toBe(true);
expect(stopTarget()?.id).toBe(80);
handleDebugEvent(81, { kind: "terminated" });
selectSession(81);
// The finished session's tab: Stop is off although the server still runs.
expect(getContext().debugSessionActive).toBe(true);
expect(getContext().debugCanStop).toBe(false);
expect(stopTarget()).toBeNull();
selectSession(80);
expect(getContext().debugCanStop).toBe(true);
handleDebugEvent(80, { kind: "terminated" });
});
it("ignores sessions this window did not start, but adopts children of its own", async () => {
vi.spyOn(console, "warn").mockImplementation(() => {});
adoptSession(90, { name: "app", adapter: "js-debug" });
+3 -2
Переглянути файл
@@ -79,6 +79,7 @@ import {
startPreparedSession,
stopSession,
stopAssociatedProcess,
stopTarget,
useDebug,
type DebugSession,
} from "./state";
@@ -560,9 +561,9 @@ export function registerDebugActions(): () => void {
title: "Stop",
category: "Debug",
icon: "stop",
when: "debugSessionActive",
when: "debugCanStop",
run: () => {
const s = activeSession() ?? Object.values(useDebug.getState().sessions).find(isLive);
const s = stopTarget();
if (s) void stopSession(s.id);
},
},
+9
Переглянути файл
@@ -197,6 +197,13 @@ export function isLive(s: DebugSession | null | undefined): boolean {
return !!s && s.status !== "terminated";
}
/** The session the Debug tool window's Stop acts on: the selected one while it runs (any live one when none is selected). */
export function stopTarget(): DebugSession | null {
const s = activeSession();
if (s) return isLive(s) ? s : null;
return Object.values(useDebug.getState().sessions).find(isLive) ?? null;
}
/** Whether the session with this id is still there and running, as of now. */
export const isLiveSession = (id: DebugSessionId) => isLive(useDebug.getState().sessions[id]);
@@ -405,6 +412,8 @@ export function publishContext() {
});
const anyLive = Object.values(useDebug.getState().sessions).some(isLive);
setContext("debugSessionActive", anyLive);
// Stop acts on the selected session tab, so a finished one doesn't stop another session.
setContext("debugCanStop", !!stopTarget());
setContext("debugSessionRunning", s?.status === "running");
setContext("debugSessionPaused", s?.status === "paused");
// Dart and Flutter sessions: Hot Reload / Hot Restart.