дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Closing a remote window (SSH, WSL, Dev Containers) used to end openidea-server --stdio and tear down terminals, runs (running their stop commands), indexing and agent turns. openidea-server --attach now connects through a detached per-project daemon (private 0700 run dir, owner check, flock) that keeps them alive across disconnects; reopening reattaches terminals with bounded scrollback and OSC state, runs and agent turns, and restores remote editor tabs, tool windows and plugin views. The close dialog offers Keep Backend Running / Stop Backend; Stop Remote Backend shuts the daemon down on demand. A disconnected backend with no live work exits after an idle timeout (3 hours by default; presets, custom or Never in Settings › Tools › Remote Development, host override wins). The socket is keyed by project, so a new build replaces an idle backend of another build and reports a busy one; a window taken over by another shows that instead of a dropped connection. Clean documents are released on disconnect while dirty buffers keep the backend alive. Also: a plugin-owned PTY keeps its exit hook across reattach (reattach only rebinds the forwarding sink), and a recent project clicked again while it is still opening joins that attempt instead of connecting twice (a double click made the second attach take over and fail the first). Co-authored-by: dengliu <[email protected]>
991 рядки
37 KiB
TypeScript
991 рядки
37 KiB
TypeScript
/**
|
|
* Run configurations, the title bar run widget, the Run tool window (console +
|
|
* test runner) and run/debug/stop actions.
|
|
*/
|
|
import { registerEditorContribution } from "@/editor/api";
|
|
import { executeAction, executeActionOrThrow, getAction, registerActions } from "@/platform/actions";
|
|
import { getContext, setContext, useContextKeys } from "@/platform/context";
|
|
import { call, commands, onIdeEvent, type RunConfig } from "@/platform/ipc";
|
|
import { projectFolder, useProject } from "@/platform/project";
|
|
import { parseRemoteLocation, projectLocation } from "@/platform/remote";
|
|
import { isSameOrInside } from "@/platform/paths";
|
|
import { agentRunSettings, onWorkflowSettingsChange } from "@/platform/workflowSettings";
|
|
import { showContextMenu, lazyComponent, lazyWhen, type MenuItem } from "@/ui";
|
|
import {
|
|
menuGroupItems,
|
|
useDebugRunSessions,
|
|
notifications,
|
|
provideRunConfigurationChecks,
|
|
provideRunConfigurationLookup,
|
|
provideRunOutput,
|
|
registerMenuGroup,
|
|
registerOverlay,
|
|
registerRunAnythingProvider,
|
|
registerRunConfigType,
|
|
registerRunningProcessesProvider,
|
|
registerServiceProvider,
|
|
registerTitleItem,
|
|
registerToolWindow,
|
|
} from "@/workbench/contributions";
|
|
import { restartFlutterDaemon, selectFlutterDevice, useFlutterDevices } from "@/workbench/flutterDevices";
|
|
import { chooserJustClosed, ConfigChooserOverlay } from "./ConfigChooser";
|
|
import {
|
|
compiledDebugPlan,
|
|
contextMenuItems,
|
|
executeContext,
|
|
debugBinary,
|
|
modifyContext,
|
|
prepareMenu,
|
|
runContextAction,
|
|
} from "./contextRun";
|
|
import { runWithExecutor } from "./executors";
|
|
import { notifyCwdError, withExpandedCwd } from "./cwdMacros";
|
|
import { debugWithAgent, jdwpLaunch } from "./javaDebug";
|
|
import { attachesToChild, debugAttachingToChild } from "./pluginAttach";
|
|
import { RunDialogsOverlay } from "./dialogs";
|
|
import { registerExternalTools } from "./externalTools";
|
|
import { openImport } from "./importConfigs";
|
|
import { registerComposerInstall } from "./composerInstall";
|
|
import { registerGoActions } from "./goActions";
|
|
import { registerRunTabActions } from "./runTabs";
|
|
import { invalidateGoModules } from "./goModules";
|
|
import { invalidatePythonPackages } from "./pythonPackages";
|
|
import { RunWidget } from "./RunWidget";
|
|
import { runConfigsRunAnything } from "./runAnything";
|
|
import { runDirectory } from "./navigate";
|
|
import {
|
|
cleanupRemovedProject,
|
|
registerRunServiceActions,
|
|
runServiceProvider,
|
|
watchServiceRunningCount,
|
|
} from "./services";
|
|
import { liveServiceSession, serviceSessions } from "./serviceSessions";
|
|
import { ServiceImportHost } from "./serviceImport";
|
|
import { cmakeBuildId } from "./cmake";
|
|
import { configurationChecks } from "./configurationChecks";
|
|
import { runBeforeLaunch } from "./beforeLaunch";
|
|
import { compoundChildren } from "./configs";
|
|
import { containerDebuggable, remoteDebugBlocked } from "./remote";
|
|
import { debugInContainer } from "./containerDebug";
|
|
import { isDebugOnly, registerBuiltinTypes } from "./types";
|
|
import { isZigBuildStep, zigDebugTarget } from "./zigDebug";
|
|
import { junitType } from "./junitType";
|
|
import { listenForApplicationDeactivation, showApplicationUpdate, updatableSessions } from "./applicationUpdate";
|
|
import { hotReload, hotReloadSession, hotRestart } from "./flutterHotReload";
|
|
import { npmGutter } from "./npmGutter";
|
|
import { launchSettingsGutter } from "./launchSettingsGutter";
|
|
import { runGutter } from "./runGutter";
|
|
import { markdownCommandGutter } from "./markdownCommands";
|
|
import { gradleDelegation } from "./gradleRun";
|
|
import { activateStackTrace, useStackTraces } from "./stackTrace";
|
|
import { clearRuntimeCache } from "./runtimes";
|
|
import {
|
|
adoptTemporary,
|
|
applyConsoleSettings,
|
|
CURRENT_FILE,
|
|
currentFileSelected,
|
|
prepareLaunch,
|
|
rescheduleConsoleFlushes,
|
|
setBeforeLaunchRunner,
|
|
loadConfigs,
|
|
failedTests,
|
|
baseConfigOf,
|
|
onRunExited,
|
|
rerunFailed,
|
|
rerunSession,
|
|
resetRuns,
|
|
runningSessions,
|
|
saveUserConfigs,
|
|
dropStaleContextConfigs,
|
|
selectConfig,
|
|
selectedConfig,
|
|
startRun,
|
|
debugSingleInstance,
|
|
startSampleOutput,
|
|
stopSession,
|
|
subscribeOutput,
|
|
trackRecentConfigurations,
|
|
useRun,
|
|
isLive,
|
|
} from "./store";
|
|
import { rerunFailedConfigs } from "./testing/rerun";
|
|
import { TEST_TREE_FOCUS, testTree } from "./testTree";
|
|
import { startAgentRun, trimAgentArchive, type AgentRunRequest } from "./agentRuns";
|
|
import { compoundTargets, selectedTarget } from "./sessionTargets";
|
|
import { tx } from "@/platform/i18n";
|
|
import { UNITY_CONFIG_KIND, showUnityAttach } from "./unity";
|
|
|
|
function trackFailedTestSelection(): () => void {
|
|
let signature = "";
|
|
let generation = 0;
|
|
const update = () => {
|
|
const state = useRun.getState();
|
|
const id =
|
|
(state.activeSession && failedTests(state.activeSession).length ? state.activeSession : null) ??
|
|
[...state.sessions].reverse().find((s) => failedTests(s.id).length > 0)?.id;
|
|
const session = state.sessions.find((s) => s.id === id);
|
|
const base = session && baseConfigOf(session);
|
|
const paths = id ? failedTests(id) : [];
|
|
const next = JSON.stringify([id, session?.status, base, paths]);
|
|
if (next === signature) return;
|
|
signature = next;
|
|
const request = ++generation;
|
|
setContext("run.canRerunFailed", false);
|
|
if (!session || isLive(session) || !base) return;
|
|
const selection = rerunFailedConfigs(base, paths);
|
|
if (selection instanceof Promise) {
|
|
void selection.then((configs) => {
|
|
if (request === generation) setContext("run.canRerunFailed", configs.length > 0);
|
|
});
|
|
} else setContext("run.canRerunFailed", selection.length > 0);
|
|
};
|
|
const stop = useRun.subscribe(update);
|
|
update();
|
|
return () => {
|
|
generation++;
|
|
stop();
|
|
setContext("run.canRerunFailed", false);
|
|
};
|
|
}
|
|
|
|
function hasProject() {
|
|
return !!useProject.getState().project;
|
|
}
|
|
|
|
async function ensureConfigs() {
|
|
if (!useRun.getState().loaded) await loadConfigs();
|
|
}
|
|
|
|
async function runSelected() {
|
|
await ensureConfigs();
|
|
if (currentFileSelected()) return runCurrentFile(false);
|
|
const config = selectedConfig();
|
|
if (!config) {
|
|
useRun.setState({ chooserOpen: true, chooserMode: "run" });
|
|
return;
|
|
}
|
|
// As in IDEA, Run starts another instance of a configuration that allows multiple instances;
|
|
// otherwise it restarts the running one.
|
|
const target = config.allowParallel
|
|
? null
|
|
: selectedTarget(config.id, useRun.getState().sessions, useDebugRunSessions.getState().sessions);
|
|
if (target) {
|
|
target.rerun?.();
|
|
return;
|
|
}
|
|
await startRun(config);
|
|
}
|
|
|
|
async function debugConfig(config: RunConfig, chain: readonly string[] = [], show?: boolean) {
|
|
if (config.kind === "compound") {
|
|
if (!(await prepareLaunch(config, chain, show))) return;
|
|
const children = compoundChildren(config, useRun.getState().configs);
|
|
await Promise.all(children.map((c) => debugConfig(c, [...chain, config.id], show)));
|
|
return;
|
|
}
|
|
if (remoteDebugBlocked(config)) return;
|
|
await debugSingleInstance(config, () => debugLaunch(config, chain, show));
|
|
}
|
|
|
|
async function debugLaunch(config: RunConfig, chain: readonly string[], show?: boolean): Promise<void> {
|
|
try {
|
|
config = await withExpandedCwd(config);
|
|
} catch (e) {
|
|
return notifyCwdError(config, e);
|
|
}
|
|
if (!(await prepareLaunch(config, chain, show))) return;
|
|
if (config.kind === UNITY_CONFIG_KIND) return showUnityAttach(config);
|
|
// Python on a Docker / Compose target: debugpy in the container, the debugger attaches.
|
|
if (containerDebuggable(config) && getAction("debug.attach")) {
|
|
await debugInContainer(config);
|
|
return;
|
|
}
|
|
// A plugin configuration whose debugger attaches to a process the run starts.
|
|
if (attachesToChild(config) && getAction("debug.attach")) {
|
|
await debugAttachingToChild(config, { show, prepared: true });
|
|
return;
|
|
}
|
|
// Remote JVM Debug, Go Remote…: the debugger attaches, nothing is launched here.
|
|
if (isDebugOnly(config) && getAction("debug.startConfig")) {
|
|
await executeAction("debug.startConfig", show === false ? { config, show: false } : config);
|
|
return;
|
|
}
|
|
// A single compiled file (rustc / clang / zig): build with debug info, then debug the binary.
|
|
const compiled = await compiledDebugPlan(config);
|
|
if (compiled?.debug) {
|
|
await debugBinary(compiled.debug, config, show);
|
|
return;
|
|
}
|
|
// "Build and run using: Gradle": the JavaExec JVM gets the agent, the debugger attaches to it.
|
|
let delegated: RunConfig | null;
|
|
try {
|
|
delegated = getAction("debug.attach") ? await gradleDelegation(config) : null;
|
|
} catch (error) {
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "error",
|
|
title: `Cannot run '${config.name}'`,
|
|
body: error instanceof Error ? error.message : String(error),
|
|
});
|
|
return;
|
|
}
|
|
if (delegated) {
|
|
await debugWithAgent(delegated, show);
|
|
return;
|
|
}
|
|
// Maven / Gradle: the build tool starts the JVM with a debug agent, the debugger attaches.
|
|
if (jdwpLaunch(config) && getAction("debug.attach")) {
|
|
await debugWithAgent(config, show);
|
|
return;
|
|
}
|
|
// `zig build run` (and other steps that run an executable) have no adapter of their own: debug
|
|
// through the executable config, which builds the binary first and launches it under CodeLLDB.
|
|
if (isZigBuildStep(config)) {
|
|
const target = zigDebugTarget(config, useRun.getState().configs);
|
|
if (target && getAction("debug.startConfig")) {
|
|
// Run the executable's before-launch build, then keep the clicked step as the session's
|
|
// origin so the Run widget, tab identity, rerun and stop follow what the user asked to debug.
|
|
if (!(await prepareLaunch(target, [config.id], show))) return;
|
|
await executeAction(
|
|
"debug.startConfig",
|
|
show === false ? { config: target, origin: config, show: false } : { config: target, origin: config },
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
if (getAction("debug.startConfig")) {
|
|
await executeAction("debug.startConfig", show === false ? { config, show: false } : config);
|
|
return;
|
|
}
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "warning",
|
|
title: "Debugger is not available",
|
|
body: tx`Running '${config.name}' without the debugger.`,
|
|
key: "run-no-debugger",
|
|
});
|
|
await startRun(config, undefined, undefined, { prepared: true, show });
|
|
}
|
|
|
|
async function debugSelected() {
|
|
await ensureConfigs();
|
|
if (currentFileSelected()) return runCurrentFile(true);
|
|
const config = selectedConfig();
|
|
if (!config) {
|
|
useRun.setState({ chooserOpen: true, chooserMode: "debug" });
|
|
return;
|
|
}
|
|
await debugConfig(config);
|
|
}
|
|
|
|
async function runContext(debug: boolean, arg?: unknown) {
|
|
if (!(await runContextAction(debug, arg))) nothingToRun();
|
|
}
|
|
|
|
/** "Current File" stays selected after running the file's context (which adopts a temporary configuration). */
|
|
async function runCurrentFile(debug: boolean) {
|
|
await runContext(debug);
|
|
selectConfig(CURRENT_FILE);
|
|
}
|
|
|
|
function nothingToRun() {
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "info",
|
|
title: "Nothing to run here",
|
|
body: "The active file has no runnable element, test or run configuration.",
|
|
key: "run-context",
|
|
});
|
|
}
|
|
|
|
/**
|
|
* The configuration an action argument names: a config id, a `RunConfig`, or
|
|
* `{ config, temporary: true }` (Maven / Gradle tool windows: becomes a temporary configuration, like IDEA).
|
|
*/
|
|
function configFromArg(arg: unknown): RunConfig | undefined {
|
|
if (typeof arg === "string") return useRun.getState().configs.find((c) => c.id === arg);
|
|
if (!arg || typeof arg !== "object") return undefined;
|
|
if ("config" in arg) {
|
|
const { config, temporary } = arg as { config: RunConfig; temporary?: boolean };
|
|
return temporary ? adoptTemporary(config) : config;
|
|
}
|
|
return arg as RunConfig;
|
|
}
|
|
|
|
/**
|
|
* Stop: in the Run or Debug tool window, the selected tab's process; otherwise the selected
|
|
* configuration's session, or a chooser of every running process.
|
|
*/
|
|
/**
|
|
* Stop. In the Run tool window: its active tab. From the run widget (`arg` "widget"): the selected
|
|
* configuration's process. Elsewhere (shortcut, menu, Find Action), like IDEA's Stop: the only
|
|
* stoppable process, or a list of them with Stop All when there are several.
|
|
*/
|
|
function stopAction(arg?: unknown) {
|
|
const ctx = getContext();
|
|
if (ctx.toolWindowFocus && ctx.activeToolWindow === "debug" && getAction("debug.stop")) {
|
|
void executeAction("debug.stop");
|
|
return;
|
|
}
|
|
const running = runningSessions();
|
|
if (ctx.toolWindowFocus && ctx.activeToolWindow === "run") {
|
|
const active = running.find((s) => s.id === useRun.getState().activeSession);
|
|
if (active) {
|
|
void stopSession(active.id);
|
|
return;
|
|
}
|
|
}
|
|
const debug = useDebugRunSessions.getState().sessions;
|
|
if (arg === "widget") {
|
|
const compound = compoundTargets(selectedConfig(), running, debug);
|
|
if (compound.length) {
|
|
compound.forEach((s) => s.stop());
|
|
return;
|
|
}
|
|
const target = selectedTarget(useRun.getState().selectedId, running, debug);
|
|
if (target) {
|
|
target.stop();
|
|
return;
|
|
}
|
|
}
|
|
const items = [
|
|
...running.map((s): MenuItem => ({
|
|
label: s.config.name,
|
|
verbatim: true,
|
|
icon: "run",
|
|
run: () => void stopSession(s.id),
|
|
})),
|
|
...menuGroupItems("stopProcess", { paths: [] }),
|
|
].filter((i): i is MenuItem & { run: () => void } => "run" in i && !!i.run);
|
|
// A Debug launch has no Run process: with nothing else to stop, the title-bar Stop reaches
|
|
// the debug session itself (the Debug window need not be focused).
|
|
if (items.length === 0) {
|
|
if (debug.length === 0) return;
|
|
if (debug.length === 1) {
|
|
debug[0]!.stop();
|
|
return;
|
|
}
|
|
const anchor = document.querySelector("[data-run-chooser]")?.getBoundingClientRect();
|
|
const at = anchor ? { x: anchor.left, y: anchor.bottom + 4 } : { x: window.innerWidth / 2 - 120, y: 44 };
|
|
showContextMenu(at, [
|
|
{ kind: "header", label: "Stop Process" },
|
|
...debug.map((s): MenuItem => ({ label: s.name, verbatim: true, icon: "debug", run: () => s.stop() })),
|
|
]);
|
|
return;
|
|
}
|
|
if (items.length === 1) {
|
|
items[0]!.run();
|
|
return;
|
|
}
|
|
const anchor = document.querySelector("[data-run-chooser]")?.getBoundingClientRect();
|
|
const at = anchor ? { x: anchor.left, y: anchor.bottom + 4 } : { x: window.innerWidth / 2 - 120, y: 44 };
|
|
showContextMenu(at, [
|
|
{ kind: "header", label: "Stop Process" },
|
|
...items,
|
|
{ kind: "separator" },
|
|
{ label: "Stop All", icon: "stop", danger: true, run: () => items.forEach((i) => i.run()) },
|
|
]);
|
|
}
|
|
|
|
/** IDEA's Rerun (⌘R / Ctrl+F5 in the Run tool window): restarts the selected tab without asking. */
|
|
function rerunActive() {
|
|
const { activeSession, sessions } = useRun.getState();
|
|
const id = activeSession ?? sessions[sessions.length - 1]?.id;
|
|
if (id) rerunSession(id);
|
|
}
|
|
|
|
function useRunningCount(): number | null {
|
|
return useRun((s) => s.sessions.filter(isLive).length || null);
|
|
}
|
|
|
|
const CONFIG_FILES =
|
|
/(?:^|\/)(?:\.openidea\/run(?:\.local)?\.toml|package\.json|deno\.jsonc?|Cargo\.toml|build\.gradle(?:\.kts)?|pom\.xml|go\.(?:mod|work)|pyproject\.toml|setup\.cfg|pytest\.ini|manage\.py|Makefile|justfile|CMakeLists\.txt|CMakeCache\.txt|index-[^/]+\.json)$/;
|
|
|
|
let reloadTimer: ReturnType<typeof setTimeout> | undefined;
|
|
function scheduleReload() {
|
|
clearTimeout(reloadTimer);
|
|
reloadTimer = setTimeout(() => void loadConfigs(), 300);
|
|
}
|
|
|
|
const useEditConfigsOpen = () => useRun((s) => s.editorOpen);
|
|
|
|
export function activate(): () => void {
|
|
const disposers: Array<() => void> = [
|
|
// The performance harness (`perf/`): a console streaming generated output.
|
|
import.meta.env.DEV || import.meta.env.MODE === "perf"
|
|
? registerActions([
|
|
{
|
|
id: "run.sampleOutput",
|
|
title: "Stream Sample Output",
|
|
category: "Run",
|
|
hidden: true,
|
|
run: async ({ arg }) => {
|
|
const { lines = 20_000, perFrame = 200 } = (arg ?? {}) as { lines?: number; perFrame?: number };
|
|
await startSampleOutput(lines, perFrame);
|
|
},
|
|
},
|
|
])
|
|
: () => {},
|
|
registerToolWindow({
|
|
id: "run",
|
|
title: "Run",
|
|
icon: "toolwindow-run",
|
|
anchor: "bottom",
|
|
stripe: "onUse",
|
|
sessionContent: true,
|
|
order: 5,
|
|
component: lazyComponent(() => import("./RunView").then((m) => m.RunView)),
|
|
headerContent: lazyComponent(() => import("./RunView").then((m) => m.RunTabs)),
|
|
useBadge: useRunningCount,
|
|
}),
|
|
registerTitleItem({ id: "run.widget", title: "Run Widget", align: "right", priority: 0, component: RunWidget }),
|
|
registerRunAnythingProvider(runConfigsRunAnything),
|
|
registerBuiltinTypes(),
|
|
registerRunConfigType(junitType),
|
|
registerGoActions(),
|
|
registerRunTabActions(),
|
|
registerComposerInstall(),
|
|
registerOverlay({ id: "run.chooser", component: ConfigChooserOverlay }),
|
|
registerOverlay({
|
|
id: "run.editConfigs",
|
|
component: lazyWhen(useEditConfigsOpen, () => import("./EditConfigsDialog").then((m) => m.EditConfigsOverlay)),
|
|
}),
|
|
registerOverlay({ id: "run.dialogs", component: RunDialogsOverlay }),
|
|
registerOverlay({ id: "run.serviceImport", component: ServiceImportHost }),
|
|
registerOverlay({ id: "run.serviceImport", component: ServiceImportHost }),
|
|
registerServiceProvider(runServiceProvider),
|
|
registerRunServiceActions(),
|
|
watchServiceRunningCount(),
|
|
registerRunningProcessesProvider({
|
|
id: "run",
|
|
running: () =>
|
|
serviceSessions(useRun.getState().sessions, useDebugRunSessions.getState().serviceSessions)
|
|
.filter(liveServiceSession)
|
|
.map((s) => ({ name: s.config.name })),
|
|
// A closing window asks first, then shows the progress while these shut down; `kill`
|
|
// is the second Stop that SIGKILLs instead of waiting.
|
|
stop: (kill) => {
|
|
// The first call asks to stop; with `kill` the second one reaches the backend while
|
|
// the session is already stopping, which turns it into SIGKILL.
|
|
for (const s of useRun.getState().sessions.filter(isLive)) {
|
|
void stopSession(s.id);
|
|
if (kill) void stopSession(s.id);
|
|
}
|
|
for (const d of useDebugRunSessions.getState().sessions) {
|
|
d.stop();
|
|
if (kill) d.stop();
|
|
}
|
|
},
|
|
}),
|
|
onWorkflowSettingsChange((w) => w.console, applyConsoleSettings),
|
|
registerExternalTools(),
|
|
activateStackTrace(),
|
|
listenForApplicationDeactivation(),
|
|
trackRecentConfigurations(),
|
|
trackFailedTestSelection(),
|
|
useDebugRunSessions.subscribe(() => setContext("run.updatableRunning", updatableSessions().length > 0)),
|
|
// A removed workspace member (or a closed project) takes its sessions,
|
|
// temporary configurations and Services groups with it.
|
|
// Only while the same project stays open: closing it tears its runs down separately.
|
|
useProject.subscribe((s, prev) => {
|
|
if (!s.project || s.project.root !== prev.project?.root) return;
|
|
const before = prev.project.workspace?.projects ?? [prev.project.root];
|
|
const after = s.project.workspace?.projects ?? [s.project.root];
|
|
for (const root of before) if (!after.includes(root)) void cleanupRemovedProject(root);
|
|
}),
|
|
registerEditorContribution({ id: "run.targets", order: 55, extensions: runGutter }),
|
|
registerEditorContribution({ id: "run.npmScripts", order: 58, extensions: npmGutter }),
|
|
registerEditorContribution({ id: "run.markdownCommands", order: 58, extensions: markdownCommandGutter }),
|
|
registerEditorContribution({ id: "run.launchSettings", order: 58, extensions: launchSettingsGutter }),
|
|
registerMenuGroup({
|
|
id: "run.context",
|
|
menus: ["editor", "projectView", "editorTab"],
|
|
items: contextMenuItems,
|
|
prepare: prepareMenu,
|
|
}),
|
|
registerActions([
|
|
{
|
|
id: "run.updateApplication",
|
|
title: "Update Application",
|
|
category: "Run",
|
|
icon: "refresh",
|
|
when: "run.updatableRunning",
|
|
run: () => showApplicationUpdate(),
|
|
},
|
|
{
|
|
id: "run.run",
|
|
title: "Run",
|
|
category: "Run",
|
|
icon: "run",
|
|
when: "projectOpen",
|
|
run: () => runSelected(),
|
|
},
|
|
{
|
|
id: "run.debug",
|
|
title: "Debug",
|
|
category: "Run",
|
|
icon: "debug",
|
|
when: "projectOpen",
|
|
run: () => debugSelected(),
|
|
},
|
|
{
|
|
id: "run.attachUnity",
|
|
title: "Attach to Unity Process",
|
|
category: "Run",
|
|
icon: "debug",
|
|
when: "projectOpen",
|
|
run: () => showUnityAttach(),
|
|
},
|
|
{
|
|
id: "run.runContext",
|
|
title: "Run Context Configuration",
|
|
description: "Run the test or program in the active file",
|
|
category: "Run",
|
|
icon: "run",
|
|
when: "projectOpen",
|
|
keywords: ["run file", "run test"],
|
|
run: ({ arg }) => runContext(false, arg),
|
|
},
|
|
{
|
|
id: "run.debugContext",
|
|
title: "Debug Context Configuration",
|
|
category: "Run",
|
|
icon: "debug",
|
|
when: "projectOpen",
|
|
run: ({ arg }) => runContext(true, arg),
|
|
},
|
|
{
|
|
id: "run.modifyContext",
|
|
title: "Modify Run Configuration…",
|
|
description: "Edit the configuration that would run the context before saving it",
|
|
category: "Run",
|
|
icon: "edit",
|
|
when: "projectOpen",
|
|
run: ({ arg }) => modifyContext(arg),
|
|
},
|
|
{
|
|
id: "run.stop",
|
|
title: "Stop",
|
|
category: "Run",
|
|
icon: "stop",
|
|
when: "projectOpen",
|
|
run: ({ arg }) => stopAction(arg),
|
|
},
|
|
{
|
|
id: "run.stopProcess",
|
|
title: "Stop",
|
|
category: "Run",
|
|
hidden: true,
|
|
run: async ({ arg }) => {
|
|
if (typeof arg !== "number") return;
|
|
const session = useRun.getState().sessions.find((s) => s.runId === arg);
|
|
if (session) await stopSession(session.id);
|
|
else await call(commands.runStop(arg));
|
|
},
|
|
},
|
|
{
|
|
id: "run.rerun",
|
|
title: "Rerun",
|
|
category: "Run",
|
|
icon: "rerun",
|
|
when: "projectOpen && activeToolWindow == 'run'",
|
|
run: () => rerunActive(),
|
|
},
|
|
{
|
|
id: "run.flutterChooseDevice",
|
|
title: "Select Flutter Device…",
|
|
category: "Run",
|
|
when: "flutterProject",
|
|
run: () => {
|
|
const chooserOpen = !useFlutterDevices.getState().chooserOpen;
|
|
useFlutterDevices.setState({ chooserOpen });
|
|
if (chooserOpen) void call(commands.flutterDevicesRefresh()).catch(() => undefined);
|
|
},
|
|
},
|
|
{
|
|
id: "run.flutterSelectDevice",
|
|
title: "Use Flutter Device",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "flutterProject",
|
|
run: ({ arg }) => {
|
|
if (typeof arg === "string") selectFlutterDevice(arg);
|
|
},
|
|
},
|
|
{
|
|
id: "run.flutterRestartDaemon",
|
|
title: "Restart Flutter Daemon",
|
|
category: "Run",
|
|
when: "flutterProject",
|
|
run: () => restartFlutterDaemon(),
|
|
},
|
|
{
|
|
id: "run.flutterHotReload",
|
|
title: "Hot Reload",
|
|
category: "Run",
|
|
icon: "hot-reload",
|
|
description: "Flutter: inject the changed sources into the running app",
|
|
when: "run.flutterHotReloadable",
|
|
run: () => {
|
|
const session = hotReloadSession();
|
|
if (session) hotReload(session.id);
|
|
},
|
|
},
|
|
{
|
|
id: "run.flutterHotRestart",
|
|
title: "Hot Restart",
|
|
category: "Run",
|
|
icon: "refresh",
|
|
description: "Flutter: restart the app, discarding its state",
|
|
when: "run.flutterHotReloadable",
|
|
run: () => {
|
|
const session = hotReloadSession();
|
|
if (session) hotRestart(session.id);
|
|
},
|
|
},
|
|
{
|
|
id: "run.chooseConfig",
|
|
title: "Select Run/Debug Configuration…",
|
|
description:
|
|
'Run a configuration (hold Shift to debug); the title bar widget passes "select" to only select one',
|
|
category: "Run",
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
if (useRun.getState().chooserOpen || chooserJustClosed()) {
|
|
useRun.setState({ chooserOpen: false });
|
|
return;
|
|
}
|
|
await ensureConfigs();
|
|
useRun.setState({ chooserOpen: true, chooserMode: arg === "select" ? "select" : "run" });
|
|
},
|
|
},
|
|
{
|
|
id: "run.chooseDebugConfig",
|
|
title: "Debug…",
|
|
description: "Choose a run/debug configuration and debug it",
|
|
category: "Run",
|
|
keywords: ["choose and debug configuration"],
|
|
when: "projectOpen",
|
|
run: async () => {
|
|
if (useRun.getState().chooserOpen || chooserJustClosed()) {
|
|
useRun.setState({ chooserOpen: false });
|
|
return;
|
|
}
|
|
await ensureConfigs();
|
|
useRun.setState({ chooserOpen: true, chooserMode: "debug" });
|
|
},
|
|
},
|
|
{
|
|
id: "run.editConfigs",
|
|
title: "Edit Configurations…",
|
|
category: "Run",
|
|
icon: "settings",
|
|
when: "projectOpen",
|
|
keywords: ["run configuration", "launch"],
|
|
run: async ({ arg }) => {
|
|
await ensureConfigs();
|
|
useRun.setState({
|
|
editorOpen: true,
|
|
chooserOpen: false,
|
|
editTarget: typeof arg === "string" ? arg : null,
|
|
});
|
|
},
|
|
},
|
|
{
|
|
id: "run.importVscodeLaunch",
|
|
title: "Import Run Configurations from .vscode/launch.json",
|
|
category: "Run",
|
|
when: "projectOpen",
|
|
keywords: ["launch.json", "vscode", "visual studio code", "debug configuration"],
|
|
run: () => openImport("vscode"),
|
|
},
|
|
{
|
|
id: "run.importJetbrains",
|
|
title: "Import Run Configurations from JetBrains (.run, .idea)",
|
|
category: "Run",
|
|
when: "projectOpen",
|
|
keywords: ["pycharm", "webstorm", "intellij", "run.xml", "workspace.xml", "run configuration"],
|
|
run: () => openImport("jetbrains"),
|
|
},
|
|
{
|
|
id: "run.debugConfig",
|
|
title: "Debug Configuration",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
await ensureConfigs();
|
|
const config = configFromArg(arg);
|
|
const show = arg && typeof arg === "object" && "show" in arg ? (arg as { show?: boolean }).show : undefined;
|
|
if (config) await debugConfig(config, [], show);
|
|
},
|
|
},
|
|
{
|
|
id: "run.rerunFailed",
|
|
title: "Rerun Failed Tests",
|
|
category: "Run",
|
|
icon: "rerun",
|
|
when: "projectOpen && run.canRerunFailed",
|
|
keywords: ["failed tests", "rerun"],
|
|
run: async () => {
|
|
const s = useRun.getState();
|
|
const id =
|
|
(s.activeSession && failedTests(s.activeSession).length ? s.activeSession : null) ??
|
|
[...s.sessions].reverse().find((x) => failedTests(x.id).length > 0)?.id;
|
|
if (!id || !(await rerunFailed(id)))
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "info",
|
|
title: "No failed tests to rerun",
|
|
key: "run-rerun-failed",
|
|
});
|
|
},
|
|
},
|
|
{
|
|
id: "run.expandAllTests",
|
|
title: "Expand All",
|
|
category: "Run",
|
|
icon: "expand-all",
|
|
when: "projectOpen && activeToolWindow == 'run'",
|
|
keyWhen: TEST_TREE_FOCUS,
|
|
run: () => testTree.expandAll?.(),
|
|
},
|
|
{
|
|
id: "run.collapseAllTests",
|
|
title: "Collapse All",
|
|
category: "Run",
|
|
icon: "collapse-all",
|
|
when: "projectOpen && activeToolWindow == 'run'",
|
|
keyWhen: TEST_TREE_FOCUS,
|
|
run: () => testTree.collapseAll?.(),
|
|
},
|
|
{
|
|
id: "run.exportTestResults",
|
|
title: "Export Test Results…",
|
|
description: "Save the test results as an HTML report or IDEA's XML",
|
|
category: "Run",
|
|
icon: "export",
|
|
when: "projectOpen && activeToolWindow == 'run'",
|
|
keywords: ["test", "results", "report", "html", "xml", "save"],
|
|
enabled: () => testTree.exportResults !== null,
|
|
run: () => testTree.exportResults?.(),
|
|
},
|
|
{
|
|
id: "run.toggleTestDurations",
|
|
title: "Show Test Durations",
|
|
category: "Run",
|
|
when: "projectOpen",
|
|
enabled: () => testTree.toggleDurations !== null,
|
|
toggled: () => testTree.showDurations === true,
|
|
run: () => testTree.toggleDurations?.(),
|
|
},
|
|
{
|
|
id: "run.reloadConfigs",
|
|
title: "Reload Run Configurations",
|
|
category: "Run",
|
|
icon: "refresh",
|
|
when: "projectOpen",
|
|
run: () => {
|
|
clearRuntimeCache();
|
|
return loadConfigs();
|
|
},
|
|
},
|
|
{
|
|
id: "run.agentStart",
|
|
title: "Run Agent Command",
|
|
description:
|
|
"Runs `{ name, command, cwd, env }` from the MCP server's `run_command` in the agent tab `name`; throws when it did not start.",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: ({ arg }) => startAgentRun(arg as AgentRunRequest),
|
|
},
|
|
{
|
|
id: "run.pluginStart",
|
|
title: "Run Plugin Configuration",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
const a = arg as {
|
|
config: import("@/bindings").RunConfig;
|
|
debug: boolean;
|
|
onExit: (code: number | null, stopped: boolean) => void;
|
|
};
|
|
if (a.debug && attachesToChild(a.config)) {
|
|
if (!getAction("debug.attach")) throw new Error("Debugger unavailable");
|
|
const session = await debugAttachingToChild(a.config, { onExit: a.onExit });
|
|
if (!session || session.status === "failed") throw new Error("Run did not start");
|
|
if (session.runId === null && session.status === "finished") a.onExit(session.exitCode, !!session.stopped);
|
|
return;
|
|
}
|
|
if (a.debug) {
|
|
if (!getAction("debug.pluginStart")) throw new Error("Debugger unavailable");
|
|
await executeActionOrThrow("debug.pluginStart", a);
|
|
return;
|
|
}
|
|
const session = await startRun(a.config, undefined, undefined, { onExit: a.onExit });
|
|
if (!session || session.status === "failed") throw new Error("Run did not start");
|
|
if (session.runId === null && session.status === "finished") a.onExit(session.exitCode, !!session.stopped);
|
|
},
|
|
},
|
|
{
|
|
id: "run.runConfig",
|
|
title: "Run Configuration",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
await ensureConfigs();
|
|
const config = configFromArg(arg);
|
|
if (!config) return;
|
|
// `{ config, onExit }`: told when the process exits, or right away when it didn't start.
|
|
const onExit = (arg as { onExit?: (code: number | null, stopped: boolean) => void } | null)?.onExit;
|
|
if (typeof onExit !== "function") {
|
|
await startRun(config);
|
|
return;
|
|
}
|
|
const session = await startRun(config, undefined, undefined, { onExit });
|
|
if (!session || session.status === "failed") onExit(null, false);
|
|
else if (session.runId === null && session.status === "finished") onExit(session.exitCode, !!session.stopped);
|
|
},
|
|
},
|
|
{
|
|
id: "run.withExecutor",
|
|
title: "Run with Executor",
|
|
description:
|
|
"Runs with a contributed executor (`{ executor, config? }` or `{ executor, context }`): the given or selected configuration, or the context.",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
if (!arg || typeof arg !== "object" || typeof (arg as { executor?: unknown }).executor !== "string") return;
|
|
const { executor, config, context } = arg as { executor: string; config?: unknown; context?: unknown };
|
|
if (context !== undefined) {
|
|
if (!(await executeContext(executor, context === true ? undefined : context))) nothingToRun();
|
|
return;
|
|
}
|
|
await ensureConfigs();
|
|
if (config === undefined && currentFileSelected()) {
|
|
if (!(await executeContext(executor, undefined))) nothingToRun();
|
|
return;
|
|
}
|
|
const target = config !== undefined ? configFromArg(config) : selectedConfig();
|
|
if (!target) {
|
|
useRun.setState({ chooserOpen: true, chooserMode: "run" });
|
|
return;
|
|
}
|
|
await runWithExecutor(target, executor);
|
|
},
|
|
},
|
|
{
|
|
id: "run.createConfig",
|
|
title: "Create Run Configuration",
|
|
description: "Saves the given `RunConfig` as a user configuration and opens it in Edit Configurations.",
|
|
category: "Run",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: async ({ arg }) => {
|
|
if (!arg || typeof arg !== "object") return;
|
|
await ensureConfigs();
|
|
const config: RunConfig = { ...(arg as RunConfig), detected: false };
|
|
const { configs, temporary } = useRun.getState();
|
|
const user = configs.filter((c) => !c.detected && !temporary.includes(c.id) && c.id !== config.id);
|
|
await saveUserConfigs([...user, config]);
|
|
selectConfig(config.id);
|
|
useRun.setState({ editorOpen: true, chooserOpen: false, editTarget: config.id });
|
|
},
|
|
},
|
|
]),
|
|
onIdeEvent("runExited", (e) => onRunExited(e.run, e.code)),
|
|
onIdeEvent("projectRootsChanged", scheduleReload),
|
|
// Lets other title items follow the selected configuration (e.g. Build shows only for compiled ones).
|
|
useRun.subscribe((s) => {
|
|
const selected = s.configs.find((c) => c.id === s.selectedId);
|
|
setContext("run.selectedKind", selected?.kind ?? "");
|
|
const cmake = selected ?? s.configs.find((c) => c.kind === "cmake" && c.args[0] === "--build");
|
|
setContext("run.cmakeBuild", cmakeBuildId(cmake, s.configs));
|
|
setContext("run.updatableRunning", updatableSessions().length > 0);
|
|
setContext("run.flutterHotReloadable", !!hotReloadSession());
|
|
}),
|
|
// Agent tabs (`run_command`): the archive keeps at most Settings' number of them.
|
|
useRun.subscribe((s, prev) => {
|
|
if (s.sessions !== prev.sessions) trimAgentArchive();
|
|
}),
|
|
onWorkflowSettingsChange(() => agentRunSettings(), trimAgentArchive),
|
|
(() => {
|
|
let prevLocation = projectLocation(useProject.getState().project?.root);
|
|
return useProject.subscribe((s, prev) => {
|
|
const nextLocation = projectLocation(s.project?.root);
|
|
if (nextLocation === prevLocation && s.project?.trusted === prev.project?.trusted) return;
|
|
const wasRemote = !!prevLocation && parseRemoteLocation(prevLocation) !== null;
|
|
prevLocation = nextLocation;
|
|
resetRuns(!wasRemote);
|
|
useStackTraces.setState({ tabs: [], dialog: null });
|
|
if (s.project) void loadConfigs();
|
|
});
|
|
})(),
|
|
];
|
|
|
|
setBeforeLaunchRunner(runBeforeLaunch);
|
|
disposers.push(() => setBeforeLaunchRunner(null));
|
|
provideRunConfigurationChecks(configurationChecks);
|
|
disposers.push(() => provideRunConfigurationChecks(undefined));
|
|
provideRunOutput({ subscribe: subscribeOutput });
|
|
disposers.push(() => provideRunOutput(undefined));
|
|
provideRunConfigurationLookup((kind, directory) => {
|
|
const { project } = useProject.getState();
|
|
if (!project?.trusted) return false;
|
|
const owner = projectFolder(project, directory);
|
|
if (!owner || !isSameOrInside(directory, owner.root)) return false;
|
|
return useRun.getState().configs.some((config) => {
|
|
if (config.kind !== kind) return false;
|
|
const path = runDirectory(config.module ?? config.cwd);
|
|
return isSameOrInside(path, owner.root) && projectFolder(project, path)?.root === owner.root;
|
|
});
|
|
});
|
|
disposers.push(() => provideRunConfigurationLookup(undefined));
|
|
if (hasProject()) void loadConfigs();
|
|
|
|
// Reload when run.toml or build files change on disk (cheap; detection is fast).
|
|
disposers.push(
|
|
onIdeEvent("fsChanged", (e) => {
|
|
const paths = [...e.created, ...e.modified, ...e.removed];
|
|
// A file that moved or was deleted leaves its context configuration behind.
|
|
dropStaleContextConfigs(e.removed);
|
|
if (paths.some((p) => /(?:^|\/)go\.(?:mod|work)$/.test(p))) invalidateGoModules();
|
|
if (paths.some((p) => p.endsWith("/__init__.py"))) invalidatePythonPackages();
|
|
if (paths.some((p) => CONFIG_FILES.test(p))) scheduleReload();
|
|
}),
|
|
useContextKeys.subscribe((s, prev) => {
|
|
if (prev["build.running"] && !s["build.running"]) scheduleReload();
|
|
}),
|
|
onIdeEvent("runExited", (e) => {
|
|
if (useRun.getState().sessions.some((s) => s.runId === e.run && s.config.kind === "cmake")) scheduleReload();
|
|
}),
|
|
// Detected configs carry the selected toolchains (interpreter, JDK, Maven home and options).
|
|
onIdeEvent("settingsChanged", (e) => {
|
|
if (
|
|
!e.key ||
|
|
e.key === "languages" ||
|
|
e.key.startsWith("languages.") ||
|
|
e.key === "cmake" ||
|
|
e.key.startsWith("cmake.")
|
|
)
|
|
scheduleReload();
|
|
}),
|
|
);
|
|
|
|
// Hidden tabs pause rAF: move pending console flushes to timeouts (and back on
|
|
// return) so output keeps draining while a run continues in the background.
|
|
const onVisibility = () => rescheduleConsoleFlushes();
|
|
document.addEventListener("visibilitychange", onVisibility);
|
|
disposers.push(() => document.removeEventListener("visibilitychange", onVisibility));
|
|
|
|
return () => {
|
|
clearTimeout(reloadTimer);
|
|
disposers.reverse().forEach((d) => d());
|
|
resetRuns();
|
|
};
|
|
}
|