Files
openidea/src/features/run/pluginAttach.ts
T
l0ng-ai 74e66a5dae feat(plugins): environment and debugger for plugin run configurations (API 1.9) (#3476)
Plugin run configurations could not set environment variables, and Debug
only worked when a source file in the arguments let the IDE infer a
debugger, so a plugin could run `func start` for an Azure Functions app but
not debug the worker it starts.

API 1.9 adds the optional `launch-configurations` export, preferred over
`run-configurations` when a component has both. Each configuration can add
environment variables (only names the IDE's environment doesn't already
have, like `process` commands) and name a debugger: launch the program
under a language's debugger, or run it and attach to the first process of
an Attach to Process kind that the run starts. Only the run's own
descendants are candidates; the IDE waits up to a minute while the run
lasts and otherwise leaves it running without the debugger. Remote projects
resolve the process on the server.

The SDK gets `LaunchConfigurations` / `launch_configurations`, the README
and docs describe the export, and the bundled components and fixtures are
rebuilt for 1.9.
2026-11-15 11:01:12 +08:00

39 lines
1.6 KiB
TypeScript

/**
* Plugin configurations whose debugger attaches to a process the run starts (plugin API 1.9
* `attach-child`, e.g. an Azure Functions worker started by `func start`): Debug runs the
* configuration as Run does, waits for that process and attaches the debugger to it.
*/
import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import { call, commands, type RunConfig } from "@/platform/ipc";
import { notifications } from "@/workbench/contributions";
import { startRun, type RunSession } from "./store";
export function attachesToChild(config: RunConfig): boolean {
return config.kind === "plugin" && !!config.params?.debugAttach;
}
/** Starts the run, then attaches; resolves with the run's session once it started (null when it didn't). */
export async function debugAttachingToChild(
config: RunConfig,
options: { show?: boolean; prepared?: boolean; onExit?: (code: number | null, stopped: boolean) => void } = {},
): Promise<RunSession | null> {
const session = await startRun(config, undefined, undefined, options);
const runId = session?.runId ?? null;
if (runId === null) return session;
void call(commands.pluginDebugAttachTarget(config.id, runId)).then(
(attachable) =>
executeAction("debug.attach", { attachable, process: runId, runConfig: config, show: options.show }),
(e: unknown) => {
const message = e instanceof Error ? e.message : String(e);
notifications().notify({
group: "run",
level: "warning",
title: tx("Cannot attach the debugger"),
body: tx`'${config.name}' keeps running without the debugger: ${message}`,
});
},
);
return session;
}