Files
openidea/src/platform/runTargetSelection.ts
T
l0ng-ai 047cac209b feat(plugins): plugin API 1.4 (#2207)
Plugin API 1.4: grants for unencrypted HTTP, local sockets, IDE commands and owned database sources; window status items, output channels, content tabs, editor selections, decorations, search, Problems and VCS reads; runs, keyed terminals with exit events, plugin run targets, dynamic run configurations and test parsers; language features, injections, snippets and menu locations; plugin MCP tools on the built-in server; four official API examples. Released 1.3 plugins keep working.
2026-11-09 08:40:40 +08:00

25 lines
1.1 KiB
TypeScript

import type { RunConfig } from "@/bindings";
import { validateLanguages } from "./languageSettings";
import { useProject } from "./project";
import { workflowSettings } from "./workflowSettings";
/** Mirrors ide-sdk's interpreter target selection for guards before IPC launch. */
export function withRunTarget(config: RunConfig): RunConfig {
if (config.target !== undefined && config.target !== null) return config;
const languages = validateLanguages(useProject.getState().settings?.languages);
const name = config.command
.split(/[\\/]/)
.at(-1)
?.replace(/\.(exe|cmd|bat)$/i, "");
const selected =
["php", "composer", "phpunit", "pest"].includes(name ?? "") || ["php", "composer", "phpunit"].includes(config.kind)
? languages.php.runTarget
: ["node", "npm", "npx", "pnpm", "yarn", "bun"].includes(name ?? "") ||
["node", "npm", "vitest", "jest", "mocha"].includes(config.kind)
? languages.node.runTarget
: "";
if (selected === "local") return { ...config, target: "" };
const target = selected || workflowSettings().run.defaultTarget;
return target ? { ...config, target } : config;
}