Файли
openidea/src/features/run/sessionTargets.ts
T
l0ng-ai a7b5758f5a fix(run): target the selected configuration's run or debug session from the toolbar (#326)
With several sessions running, the toolbar's Rerun and Stop could act on a different configuration than the selected one: when the selected configuration had no matching run session, the widget fell back to the most recently started session of another configuration; and debug sessions did not record the configuration they were started from, so a configuration being debugged never matched and a running npm session took over the buttons.

The widget, Run (Shift+F10) and Stop (Cmd+F2) now target the selected configuration's session, whether it was started with Run or Debug (the most recent when both exist); Rerun of a debug session reruns it in debug. When the selected configuration is not running, the widget offers Run / Debug for it, and Stop remains available for the other running sessions (with a chooser when several are running). Debug sessions keep their originating run configuration. In a focused Run or Debug tool window, Stop still stops the selected tab's process.

Fixes #318
2026-10-30 10:51:37 +08:00

33 рядки
1.4 KiB
TypeScript

import { compoundChildren } from "./configs";
import type { RunConfig } from "@/platform/ipc";
import type { DebugRunSession } from "@/workbench/contributions";
import { rerunSession, sessionsOf, stopSession, useRun, type RunSession } from "./store";
/** Selection, never tool-window focus or an unrelated process, determines the primary target. */
export function selectedTarget(selectedId: string | null, runs: RunSession[], debug: DebugRunSession[]) {
const candidates = [
...runs
.filter((s) => (s.status === "running" || s.status === "starting") && s.config.id === selectedId)
.map((s) => ({
name: s.config.name,
startedAt: s.startedAt,
debug: false,
paused: false,
rerun: () => rerunSession(s.id),
stop: () => void stopSession(s.id),
resume: () => {},
})),
...debug.filter((s) => s.configId != null && s.configId === selectedId).map((s) => ({ ...s, debug: true })),
];
return candidates.sort((a, b) => b.startedAt - a.startedAt)[0] ?? null;
}
export function compoundTargets(config: RunConfig | undefined, runs: RunSession[], debug: DebugRunSession[]) {
if (config?.kind !== "compound") return [];
const ids = new Set(compoundChildren(config, useRun.getState().configs).map((c) => c.id));
return [
...sessionsOf(config, runs).map((s) => ({ stop: () => void stopSession(s.id) })),
...debug.filter((s) => s.configId != null && ids.has(s.configId)),
];
}