дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(plugins): add plugin run targets and interpreter routing
Цей коміт міститься в:
1 джерело
7a9baac475
коміт
adc252ccd4
131 files changed
+1401
-84
No files matched your search
@@ -1208,6 +1208,8 @@ export const commands = {
|
||||
} | null, IdeError>(__TAURI_INVOKE("plugin_navigation_goto", { doc, pos })),
|
||||
pluginNavigationMarkers: (paths: string[]) => typedError<FileMarkers[], IdeError>(__TAURI_INVOKE("plugin_navigation_markers", { paths })),
|
||||
pluginEndpoints: (pluginId: string) => typedError<PluginEndpoint[], IdeError>(__TAURI_INVOKE("plugin_endpoints", { pluginId })),
|
||||
pluginRunTargets: () => typedError<RegisteredRunTarget[], IdeError>(__TAURI_INVOKE("plugin_run_targets")),
|
||||
pluginAnswerRunTarget: (id: string, useTarget: boolean) => typedError<Settings_Serialize, IdeError>(__TAURI_INVOKE("plugin_answer_run_target", { id, useTarget })),
|
||||
/** The marketplace's plugins: read again when `refresh` or when none was read yet, else the last index read. */
|
||||
pluginMarket: (refresh: boolean) => typedError<MarketPlugin[], IdeError>(__TAURI_INVOKE("plugin_market", { refresh })),
|
||||
pluginMarketUrl: () => __TAURI_INVOKE<string | null>("plugin_market_url"),
|
||||
@@ -5947,6 +5949,8 @@ export type NodeAt = {
|
||||
export type NodeSettings = {
|
||||
/** `node` executable; empty = the one on `PATH`. */
|
||||
interpreter?: string,
|
||||
/** Run PHP/Composer or Node/package-manager commands in this target; empty = project default, `local` = local. */
|
||||
runTarget?: string,
|
||||
/** `npm` | `pnpm` | `yarn`; empty = detect from the lock file / `packageManager`. */
|
||||
packageManager?: string,
|
||||
};
|
||||
@@ -6144,6 +6148,8 @@ export type PhpLevelSource =
|
||||
export type PhpSettings = {
|
||||
/** `php` CLI executable; empty = the one on `PATH`. */
|
||||
interpreter?: string,
|
||||
/** Run PHP/Composer or Node/package-manager commands in this target; empty = project default, `local` = local. */
|
||||
runTarget?: string,
|
||||
/**
|
||||
* PHP version the language server checks the code against (`7.4`); empty = from
|
||||
* `composer.json` (`config.platform.php`, else the lowest version `require.php` allows).
|
||||
@@ -6232,6 +6238,8 @@ export type PluginEvent = PluginEvent_Serialize | PluginEvent_Deserialize;
|
||||
|
||||
/** Backend → UI notifications (Tauri event `ide://plugin`). */
|
||||
export type PluginEvent_Deserialize =
|
||||
/** Project target registrations or remembered prompt answers changed. */
|
||||
({ type: "runTargetsChanged" }) & { actions?: never; arg?: never; args?: never; body?: never; cancellable?: never; capabilities?: never; chain?: never; channel?: never; column?: never; cwd?: never; done?: never; id?: never; item?: never; key?: never; level?: never; line?: never; log?: never; message?: never; newWindow?: never; path?: never; pluginId?: never; program?: never; prompt?: never; promptId?: never; ranges?: never; reply?: never; request?: never; requestId?: never; reveal?: never; root?: never; selection?: never; sets?: never; taskId?: never; text?: never; theme?: never; title?: never; total?: never; updates?: never; url?: never; value?: never; view?: never } |
|
||||
/** A window-owned operation; an empty request id queues an asynchronous run. */
|
||||
({ type: "windowRequest"; pluginId: string; requestId: string; request: WindowRequest_Deserialize }) & { actions?: never; arg?: never; args?: never; body?: never; cancellable?: never; capabilities?: never; chain?: never; channel?: never; column?: never; cwd?: never; done?: never; id?: never; item?: never; key?: never; level?: never; line?: never; log?: never; message?: never; newWindow?: never; path?: never; program?: never; prompt?: never; promptId?: never; ranges?: never; reply?: never; reveal?: never; root?: never; selection?: never; sets?: never; taskId?: never; text?: never; theme?: never; title?: never; total?: never; updates?: never; url?: never; value?: never; view?: never } |
|
||||
/** Reply to a content action in this window. */
|
||||
@@ -6324,6 +6332,8 @@ actions: NotificationAction[] }) & { arg?: never; args?: never; cancellable?: ne
|
||||
|
||||
/** Backend → UI notifications (Tauri event `ide://plugin`). */
|
||||
export type PluginEvent_Serialize =
|
||||
/** Project target registrations or remembered prompt answers changed. */
|
||||
({ type: "runTargetsChanged" }) & { actions?: never; arg?: never; args?: never; body?: never; cancellable?: never; capabilities?: never; chain?: never; channel?: never; column?: never; cwd?: never; done?: never; id?: never; item?: never; key?: never; level?: never; line?: never; log?: never; message?: never; newWindow?: never; path?: never; pluginId?: never; program?: never; prompt?: never; promptId?: never; ranges?: never; reply?: never; request?: never; requestId?: never; reveal?: never; root?: never; selection?: never; sets?: never; taskId?: never; text?: never; theme?: never; title?: never; total?: never; updates?: never; url?: never; value?: never; view?: never } |
|
||||
/** A window-owned operation; an empty request id queues an asynchronous run. */
|
||||
({ type: "windowRequest"; pluginId: string; requestId: string; request: WindowRequest_Serialize }) & { actions?: never; arg?: never; args?: never; body?: never; cancellable?: never; capabilities?: never; chain?: never; channel?: never; column?: never; cwd?: never; done?: never; id?: never; item?: never; key?: never; level?: never; line?: never; log?: never; message?: never; newWindow?: never; path?: never; program?: never; prompt?: never; promptId?: never; ranges?: never; reply?: never; reveal?: never; root?: never; selection?: never; sets?: never; taskId?: never; text?: never; theme?: never; title?: never; total?: never; updates?: never; url?: never; value?: never; view?: never } |
|
||||
/** Reply to a content action in this window. */
|
||||
@@ -6463,6 +6473,17 @@ export type PluginOutputLine = {
|
||||
text: string,
|
||||
};
|
||||
|
||||
/** A plugin-owned argv wrapper for project runs (API 1.4). */
|
||||
export type PluginRunTarget = {
|
||||
id: string,
|
||||
name: string,
|
||||
program: string,
|
||||
args: string[],
|
||||
workdirArgs: string[],
|
||||
containerRoot: string | null,
|
||||
commands: ([string, string[]])[],
|
||||
};
|
||||
|
||||
/** A secret a plugin declares, and whether the user stored it. */
|
||||
export type PluginSecretState = {
|
||||
name: string,
|
||||
@@ -7005,6 +7026,15 @@ export type ReferencesIncomplete =
|
||||
/** A native query failed; indexed anchors are still available. */
|
||||
"serverFailed";
|
||||
|
||||
export type RegisteredRunTarget = {
|
||||
/** Opaque selector id, namespaced by the host. */
|
||||
id: string,
|
||||
pluginId: string,
|
||||
pluginName: string,
|
||||
target: PluginRunTarget,
|
||||
prompt: boolean,
|
||||
};
|
||||
|
||||
/** A registry agent this machine can run (or has installed). */
|
||||
export type RegistryAgent = {
|
||||
id: string,
|
||||
@@ -7437,6 +7467,8 @@ export type RunInfo = {
|
||||
|
||||
/** Run/Debug configuration behaviour. */
|
||||
export type RunSettings = {
|
||||
/** Target for configurations without an explicit target. Empty = local. */
|
||||
defaultTarget?: string,
|
||||
confirmRerun?: boolean,
|
||||
/** Ask before closing a Run tab whose process is still running. */
|
||||
confirmTerminate?: boolean,
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { usePluginRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { withRunTarget } from "@/platform/runTargetSelection";
|
||||
import type { RegisteredRunTarget, RunConfig, Settings } from "@/bindings";
|
||||
const mocks = vi.hoisted(() => ({ list: vi.fn(), answer: vi.fn(), notify: vi.fn(), expire: vi.fn() }));
|
||||
vi.mock("../backend", () => ({ pluginsBackend: () => ({ runTargets: mocks.list, answerRunTarget: mocks.answer }) }));
|
||||
vi.mock("@/workbench/contributions", () => ({ notifications: () => ({ notify: mocks.notify, expire: mocks.expire }) }));
|
||||
import { refreshRunTargets, startRunTargets } from "../runTargets";
|
||||
const target: RegisteredRunTarget = {
|
||||
id: "plugin-target:4:testddev",
|
||||
pluginId: "test",
|
||||
pluginName: "Test",
|
||||
prompt: true,
|
||||
target: {
|
||||
id: "ddev",
|
||||
name: "DDEV",
|
||||
program: "ddev",
|
||||
args: ["exec"],
|
||||
workdirArgs: [],
|
||||
containerRoot: null,
|
||||
commands: [],
|
||||
},
|
||||
};
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useProject.setState({ project: { root: `/project-${Math.random()}` } as never, settings: {} });
|
||||
usePluginRunTargets.setState({ targets: [] });
|
||||
mocks.list.mockResolvedValue([target]);
|
||||
});
|
||||
it("loads settings-window targets after its project arrives without prompting there", async () => {
|
||||
useProject.setState({ project: null });
|
||||
const stop = startRunTargets(false);
|
||||
try {
|
||||
useProject.setState({ project: { root: "/settings-owner" } as never });
|
||||
await vi.waitFor(() => expect(usePluginRunTargets.getState().targets).toEqual([target]));
|
||||
expect(mocks.notify).not.toHaveBeenCalled();
|
||||
mocks.list.mockResolvedValue([]);
|
||||
await refreshRunTargets(false);
|
||||
expect(usePluginRunTargets.getState().targets).toEqual([]);
|
||||
expect(mocks.answer).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
stop();
|
||||
}
|
||||
});
|
||||
it("offers Use / Not now once without changing the selection on registration", async () => {
|
||||
const original = useProject.getState().settings;
|
||||
await refreshRunTargets();
|
||||
expect(useProject.getState().settings).toBe(original);
|
||||
expect(mocks.answer).not.toHaveBeenCalled();
|
||||
const notification = mocks.notify.mock.calls[0]![0];
|
||||
expect(notification.body).toBe("Use DDEV for running PHP / Node / Composer in this project?");
|
||||
expect(notification.actions.map((a: { label: string }) => a.label)).toEqual(["Use", "Not now"]);
|
||||
await refreshRunTargets();
|
||||
expect(mocks.notify).toHaveBeenCalledTimes(1);
|
||||
mocks.answer.mockResolvedValue(original);
|
||||
mocks.list.mockResolvedValue([{ ...target, prompt: false }]);
|
||||
notification.actions[1].run();
|
||||
await vi.waitFor(() => expect(mocks.answer).toHaveBeenCalledWith(target.id, false));
|
||||
expect(useProject.getState().settings).toBe(original);
|
||||
});
|
||||
it("Use applies only the host-returned settings and a removed target disappears", async () => {
|
||||
const settings: Settings = {
|
||||
run: { defaultTarget: target.id },
|
||||
languages: { php: { runTarget: target.id }, node: { runTarget: target.id } },
|
||||
};
|
||||
await refreshRunTargets();
|
||||
mocks.answer.mockResolvedValue(settings);
|
||||
mocks.list.mockResolvedValue([{ ...target, prompt: false }]);
|
||||
mocks.notify.mock.calls[0]![0].actions[0].run();
|
||||
await vi.waitFor(() => expect(useProject.getState().settings).toBe(settings));
|
||||
mocks.list.mockResolvedValue([]);
|
||||
await refreshRunTargets();
|
||||
expect(usePluginRunTargets.getState().targets).toEqual([]);
|
||||
expect(mocks.expire).toHaveBeenCalledWith(`plugin-run-target:${target.id}`);
|
||||
});
|
||||
it("explicit local and per-config selections win over interpreter and project defaults", () => {
|
||||
useProject.setState({
|
||||
settings: {
|
||||
run: { defaultTarget: "default" },
|
||||
languages: { php: { runTarget: "php-target" }, node: { runTarget: "node-target" } },
|
||||
},
|
||||
});
|
||||
const config = { command: "php", kind: "php" } as RunConfig;
|
||||
expect(withRunTarget(config).target).toBe("php-target");
|
||||
expect(withRunTarget({ ...config, command: "npm", kind: "npm" }).target).toBe("node-target");
|
||||
expect(withRunTarget({ ...config, command: "cargo", kind: "cargo" }).target).toBe("default");
|
||||
expect(withRunTarget({ ...config, target: "" }).target).toBe("");
|
||||
expect(withRunTarget({ ...config, target: "explicit" }).target).toBe("explicit");
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useProject } from "@/platform/project";
|
||||
/**
|
||||
* Plugin host backend: `plugin_*` IPC + a `plugin_subscribe` event channel in the desktop
|
||||
* app; an in-memory simulation (the bundled samples) in plain-browser
|
||||
@@ -126,6 +127,8 @@ export interface PluginsBackend {
|
||||
/** The detail tabs of item `key` in a Services or `detail = true` view. */
|
||||
serviceDetail(pluginId: string, view: string, key: string): Promise<ServiceTab[]>;
|
||||
/** The HTTP routes a plugin reports for this window's project (`[[contributes.endpoints]]`). */
|
||||
runTargets(): Promise<import("@/bindings").RegisteredRunTarget[]>;
|
||||
answerRunTarget(id: string, useTarget: boolean): Promise<import("@/bindings").Settings>;
|
||||
endpoints(pluginId: string): Promise<PluginEndpoint[]>;
|
||||
/**
|
||||
* Runs the program of node `key`'s log tab `tab` (with the toggles in `on`) and streams its
|
||||
@@ -292,6 +295,8 @@ export const tauriPluginsBackend: PluginsBackend = {
|
||||
await call(commands.pluginViewEvent(pluginId, view, event, doc, doc == null ? editorContext() : null));
|
||||
},
|
||||
serviceDetail: (pluginId, view, key) => call(commands.pluginServiceDetail(pluginId, view, key)),
|
||||
runTargets: () => call(commands.pluginRunTargets()),
|
||||
answerRunTarget: (id, useTarget) => call(commands.pluginAnswerRunTarget(id, useTarget)),
|
||||
endpoints: (pluginId) => call(commands.pluginEndpoints(pluginId)),
|
||||
serviceLog: (pluginId, view, key, tab, on, onLine, onError, onExit) => {
|
||||
const request = nextRequestId();
|
||||
@@ -651,6 +656,8 @@ export function createMemoryPluginsBackend(
|
||||
}),
|
||||
viewEvent: async () => {},
|
||||
serviceDetail: async () => [],
|
||||
runTargets: async () => [],
|
||||
answerRunTarget: async () => useProject.getState().settings as import("@/bindings").Settings,
|
||||
endpoints: async () => [],
|
||||
answerCommand: async () => {},
|
||||
finishOperation: async () => {},
|
||||
|
||||
@@ -36,6 +36,7 @@ import { defineBuiltinUiPoints } from "./points";
|
||||
import { localizeContributions, loadPluginCatalogs, usePluginCatalogs } from "./pluginText";
|
||||
import { clearUiContributions, syncUiContributions } from "./projection";
|
||||
import { handleRuntimeEvent, refreshEventKinds, startRuntimeUi } from "./runtimeUi";
|
||||
import { refreshRunTargets } from "./runTargets";
|
||||
import {
|
||||
grantPlugin,
|
||||
runPluginCommand,
|
||||
@@ -330,6 +331,7 @@ export function handlePluginEvent(e: PluginEvent) {
|
||||
*/
|
||||
export function followPluginChanges(): () => void {
|
||||
return pluginsBackend().onEvent((e) => {
|
||||
if (e.type === "runTargetsChanged") void refreshRunTargets(false).catch(() => {});
|
||||
if (e.type === "commandsChanged" || e.type === "themeChanged" || e.type === "languagesChanged")
|
||||
handlePluginEvent(e);
|
||||
});
|
||||
|
||||
@@ -35,6 +35,7 @@ import { showInstalledIntellijThemes, useIntellijThemesDialog } from "./intellij
|
||||
import { startWorkspaceContains } from "./workspaceContains";
|
||||
import { startPluginDecorations } from "./decorations";
|
||||
import { startIndexedMarkers } from "./indexedMarkers";
|
||||
import { startRunTargets } from "./runTargets";
|
||||
import { startPluginNavigation } from "./navigation";
|
||||
import { installFromDisk, refreshPlugins, reloadPlugin, SETTINGS_PAGE_ID, updateAllPlugins, usePlugins } from "./store";
|
||||
|
||||
@@ -63,6 +64,7 @@ export function activateSettingsPages(): () => void {
|
||||
provideConsentDialog(),
|
||||
defineBuiltinUiPoints(),
|
||||
followPluginChanges(),
|
||||
startRunTargets(false),
|
||||
syncProjection(),
|
||||
trackPluginTheme(),
|
||||
trackIconTheme(),
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import type { RegisteredRunTarget } from "@/bindings";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { isTauri } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { usePluginRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { pluginsBackend } from "./backend";
|
||||
|
||||
let revision = 0;
|
||||
const shown = new Set<string>();
|
||||
function clearTargets(prompts = true) {
|
||||
revision++;
|
||||
if (prompts)
|
||||
for (const target of usePluginRunTargets.getState().targets)
|
||||
notifications().expire?.(`plugin-run-target:${target.id}`);
|
||||
shown.clear();
|
||||
usePluginRunTargets.setState({ targets: [] });
|
||||
}
|
||||
export async function refreshRunTargets(prompts = true) {
|
||||
const request = ++revision;
|
||||
const root = useProject.getState().project?.root;
|
||||
if (!root) {
|
||||
clearTargets(prompts);
|
||||
return;
|
||||
}
|
||||
const targets = await pluginsBackend().runTargets();
|
||||
if (request !== revision || root !== useProject.getState().project?.root) return;
|
||||
for (const previous of prompts ? usePluginRunTargets.getState().targets : []) {
|
||||
if (!targets.some((t) => t.id === previous.id && t.prompt)) {
|
||||
notifications().expire?.(`plugin-run-target:${previous.id}`);
|
||||
shown.delete(`${root}\0${previous.id}`);
|
||||
}
|
||||
}
|
||||
usePluginRunTargets.setState({ targets });
|
||||
if (!prompts) return;
|
||||
for (const target of targets) {
|
||||
const key = `${root}\0${target.id}`;
|
||||
if (!target.prompt || shown.has(key)) continue;
|
||||
shown.add(key);
|
||||
const answer = async (use: boolean) => {
|
||||
if (root !== useProject.getState().project?.root) return;
|
||||
try {
|
||||
const settings = await pluginsBackend().answerRunTarget(target.id, use);
|
||||
if (root === useProject.getState().project?.root) useProject.setState({ settings });
|
||||
await refreshRunTargets();
|
||||
} catch (error) {
|
||||
shown.delete(key);
|
||||
notifications().notify({ group: "plugins", level: "error", title: "Run Targets", body: String(error) });
|
||||
}
|
||||
};
|
||||
notifyTarget(target, answer);
|
||||
}
|
||||
}
|
||||
function notifyTarget(target: RegisteredRunTarget, answer: (use: boolean) => Promise<void>) {
|
||||
notifications().notify({
|
||||
sticky: true,
|
||||
group: "plugins",
|
||||
key: `plugin-run-target:${target.id}`,
|
||||
level: "info",
|
||||
title: "Run Targets",
|
||||
body: tx`Use ${target.target.name} for running PHP / Node / Composer in this project?`,
|
||||
actions: [
|
||||
{ label: "Use", run: () => void answer(true) },
|
||||
{ label: "Not now", run: () => void answer(false) },
|
||||
],
|
||||
});
|
||||
}
|
||||
export function startRunTargets(prompts = true): () => void {
|
||||
if (isTauri()) void refreshRunTargets(prompts).catch(() => {});
|
||||
const unsubscribe = useProject.subscribe((s, old) => {
|
||||
if (s.project?.root === old.project?.root) return;
|
||||
clearTargets(prompts);
|
||||
void refreshRunTargets(prompts).catch(() => {});
|
||||
});
|
||||
return () => {
|
||||
unsubscribe();
|
||||
clearTargets(prompts);
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
WASM_CONTENT_VIEW,
|
||||
} from "./views/contentTab";
|
||||
import { create } from "zustand";
|
||||
import { refreshRunTargets, startRunTargets } from "./runTargets";
|
||||
import type {
|
||||
CommitAnswer,
|
||||
CommandAnswer,
|
||||
@@ -474,6 +475,9 @@ async function answerCommand(e: Extract<PluginEvent, { type: "executeCommand" }>
|
||||
/** Handles the runtime UI events; returns whether `e` was one. */
|
||||
export function handleRuntimeEvent(e: PluginEvent): boolean {
|
||||
switch (e.type) {
|
||||
case "runTargetsChanged":
|
||||
void refreshRunTargets().catch(() => {});
|
||||
return true;
|
||||
case "decorationsChanged":
|
||||
setPluginDecorations(e.pluginId, e.sets);
|
||||
return true;
|
||||
@@ -632,7 +636,13 @@ function refreshOnProjectChange(): () => void {
|
||||
|
||||
export function startRuntimeUi(): () => void {
|
||||
const stopParser = providePluginTestParser((config, chunk) => pluginsBackend().parseTestResults(config, chunk));
|
||||
const disposers = [stopParser, projectStatusItems(), trackWorkbenchEvents(), refreshOnProjectChange()];
|
||||
const disposers = [
|
||||
startRunTargets(),
|
||||
stopParser,
|
||||
projectStatusItems(),
|
||||
trackWorkbenchEvents(),
|
||||
refreshOnProjectChange(),
|
||||
];
|
||||
return () => disposers.reverse().forEach((d) => d());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Before launch list.
|
||||
*/
|
||||
import { isJvmApplication, parseJavaArgs } from "@/platform/javaLaunch";
|
||||
import { useRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode, type RefObject } from "react";
|
||||
import clsx from "clsx";
|
||||
import { isTauri, type BeforeLaunchTask, type BuildPolicy, type RunConfig } from "@/platform/ipc";
|
||||
@@ -45,7 +46,6 @@ import {
|
||||
import { gradleContainsModule } from "./gradleRun";
|
||||
import { EnvDialog } from "./EnvDialog";
|
||||
import { useBuildModel } from "@/platform/buildModel";
|
||||
import { withTarget } from "./remote";
|
||||
import { COMPOUND, formParams, terminalApplies, withParams } from "./types";
|
||||
import { TomcatSettings } from "./TomcatSettings";
|
||||
import styles from "./Run.module.css";
|
||||
@@ -243,7 +243,7 @@ function BrowseButton({
|
||||
export function ConfigForm({ config, all, type, errors, template, onChange, modifyRequest }: ConfigFormProps) {
|
||||
const openByDefault = useWorkflowSettings((s) => s.run.showOnStart);
|
||||
const externalTools = useWorkflowSettings((s) => s.externalTools);
|
||||
const runTargets = useWorkflowSettings((s) => s.runTargets);
|
||||
const runTargets = useRunTargets();
|
||||
const toolWindows = useContributions((s) => s.toolWindows);
|
||||
const tx = useTx();
|
||||
const txTemplate = useTxTemplate();
|
||||
@@ -383,6 +383,7 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
|
||||
});
|
||||
|
||||
const targetOptions: SelectOption[] = [
|
||||
{ value: "__default", label: "Default run target" },
|
||||
{ value: "", label: "Local machine" },
|
||||
...runTargets.map((t) => ({ value: t.id, label: t.name.trim() || t.id })),
|
||||
];
|
||||
@@ -446,9 +447,14 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
|
||||
}
|
||||
>
|
||||
<Select
|
||||
value={config.target ?? ""}
|
||||
value={config.target ?? "__default"}
|
||||
options={targetOptions}
|
||||
onChange={(target) => onChange(withTarget(config, target))}
|
||||
onChange={(target) => {
|
||||
if (target === "__default") {
|
||||
const { target: _target, ...rest } = config;
|
||||
onChange(rest);
|
||||
} else onChange({ ...config, target });
|
||||
}}
|
||||
aria-label="Run on"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/** Sidebar rows: type groups, their folders (first), then loose configurations; collapsed nodes hide their children. */
|
||||
import { useRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { useEffect, useMemo, useRef, useState, type DragEvent, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { call, commands, isTauri, type RunConfig, type RunImportSource } from "@/platform/ipc";
|
||||
import { letterOf } from "@/platform/keymap";
|
||||
import { useWorkflowSettings } from "@/platform/workflowSettings";
|
||||
import { Button, Dialog, Icon, IconButton, Input, T } from "@/ui";
|
||||
import {
|
||||
notifications,
|
||||
@@ -49,7 +50,6 @@ export type TreeRow =
|
||||
| { type: "folder"; key: string; kind: string; name: string }
|
||||
| { type: "config"; key: string; config: RunConfig; depth: 1 | 2 };
|
||||
|
||||
/** Sidebar rows: type groups, their folders (first), then loose configurations; collapsed nodes hide their children. */
|
||||
export function treeRows(
|
||||
configs: readonly RunConfig[],
|
||||
extraFolders: ReadonlyArray<{ kind: string; name: string }> = [],
|
||||
@@ -133,7 +133,7 @@ function EditConfigsDialog() {
|
||||
const [dirty, setDirty] = useState(() => useRun.getState().editDirty);
|
||||
const [removedDetectedIds, setRemovedDetectedIds] = useState<string[]>([]);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const runTargets = useWorkflowSettings((s) => s.runTargets);
|
||||
const runTargets = useRunTargets();
|
||||
const [adding, setAdding] = useState<{ x: number; y: number } | null>(null);
|
||||
const [modifyRequest, setModifyRequest] = useState(0);
|
||||
const addRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
@@ -41,6 +41,7 @@ import { executeAction, registerActions } from "@/platform/actions";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { IpcError, type RunConfig } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { usePluginRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { DEFAULT_RUN_TARGET, type RunTargetValid } from "@/platform/remoteSettings";
|
||||
import {
|
||||
provideNotificationService,
|
||||
@@ -96,6 +97,7 @@ const fail = (message: string, kind = "permissionDenied") => ({ status: "error"
|
||||
const notify = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
usePluginRunTargets.setState({ targets: [] });
|
||||
resetRuns();
|
||||
for (const f of Object.values(ipc)) f.mockClear();
|
||||
confirm.mockClear();
|
||||
@@ -148,13 +150,46 @@ describe("run targets", () => {
|
||||
<ConfigForm config={cfg("app")} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />,
|
||||
);
|
||||
const select = screen.getByRole("button", { name: "Run on" });
|
||||
expect(select.textContent).toContain("Local machine");
|
||||
expect(select.textContent).toContain("Default run target");
|
||||
fireEvent.click(select);
|
||||
const popup = document.querySelector("[data-autofocus]")!;
|
||||
fireEvent.keyDown(popup, { key: "ArrowDown" });
|
||||
fireEvent.keyDown(popup, { key: "ArrowDown" });
|
||||
fireEvent.keyDown(popup, { key: "Enter" });
|
||||
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ target: "box" }));
|
||||
});
|
||||
it("includes plugin targets labelled with their owner in the target selector", () => {
|
||||
const id = "plugin-target:9:executionwrapper";
|
||||
usePluginRunTargets.setState({
|
||||
targets: [
|
||||
{
|
||||
id,
|
||||
pluginId: "execution",
|
||||
pluginName: "Fixture",
|
||||
prompt: false,
|
||||
target: {
|
||||
id: "wrapper",
|
||||
name: "Execution",
|
||||
program: "wrapper",
|
||||
args: [],
|
||||
workdirArgs: [],
|
||||
containerRoot: null,
|
||||
commands: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
<ConfigForm config={cfg("app")} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />,
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Run on" }));
|
||||
const popup = document.querySelector("[data-autofocus]")!;
|
||||
expect(popup.textContent).toContain("Execution (Fixture)");
|
||||
fireEvent.keyDown(popup, { key: "End" });
|
||||
fireEvent.keyDown(popup, { key: "Enter" });
|
||||
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ target: id }));
|
||||
});
|
||||
});
|
||||
|
||||
describe("remote debugging", () => {
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
* SSH or in a Docker / Compose container. Labels, the debug and executor guards,
|
||||
* and the connection remedies of `runStart`.
|
||||
*/
|
||||
import { withRunTarget } from "@/platform/runTargetSelection";
|
||||
import { useRunTargets, runTargets as allRunTargets, type RuntimeRunTarget } from "@/platform/pluginRunTargets";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { tx, txTemplate } from "@/platform/i18n";
|
||||
import { call, commands, IpcError, type RunConfig } from "@/platform/ipc";
|
||||
import { inContainer, type RunTargetValid, type SshConfigValid } from "@/platform/remoteSettings";
|
||||
import { useWorkflowSettings, workflowSettings } from "@/platform/workflowSettings";
|
||||
import { inContainer, type SshConfigValid } from "@/platform/remoteSettings";
|
||||
import { workflowSettings } from "@/platform/workflowSettings";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { confirm } from "@/workbench/messages";
|
||||
import { promptSecret } from "./dialogs";
|
||||
@@ -15,16 +17,17 @@ import { promptSecret } from "./dialogs";
|
||||
/** The run target `config` runs on; undefined when it runs locally or the target is gone. */
|
||||
export function targetOf(
|
||||
config: Pick<RunConfig, "target">,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
): RunTargetValid | undefined {
|
||||
targets: readonly RuntimeRunTarget[] = allRunTargets(),
|
||||
): RuntimeRunTarget | undefined {
|
||||
return config.target ? targets.find((t) => t.id === config.target) : undefined;
|
||||
}
|
||||
|
||||
/** Display name of the target `config` runs on (its id when missing); null when local. */
|
||||
export function targetName(
|
||||
config: Pick<RunConfig, "target">,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
targets: readonly RuntimeRunTarget[] = allRunTargets(),
|
||||
): string | null {
|
||||
if ("command" in config) config = withRunTarget(config as RunConfig);
|
||||
if (!config.target) return null;
|
||||
const t = targetOf(config, targets);
|
||||
return t ? t.name.trim() || t.id : config.target;
|
||||
@@ -33,7 +36,7 @@ export function targetName(
|
||||
/** `name @ target` for configurations on a run target, else the name. */
|
||||
export function remoteLabel(
|
||||
config: Pick<RunConfig, "name" | "target">,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
targets: readonly RuntimeRunTarget[] = allRunTargets(),
|
||||
): string {
|
||||
const t = targetName(config, targets);
|
||||
return t ? `${config.name} @ ${t}` : config.name;
|
||||
@@ -41,20 +44,20 @@ export function remoteLabel(
|
||||
|
||||
/** `remoteLabel` that re-renders when the run targets change. */
|
||||
export function useRemoteLabel(): (config: Pick<RunConfig, "name" | "target">) => string {
|
||||
const targets = useWorkflowSettings((s) => s.runTargets);
|
||||
const targets = useRunTargets();
|
||||
return (config) => remoteLabel(config, targets);
|
||||
}
|
||||
|
||||
/** `config` running on `target` (empty: this machine, the key is dropped). */
|
||||
export function withTarget(config: RunConfig, target: string): RunConfig {
|
||||
const { target: _previous, ...rest } = config;
|
||||
return target ? { ...rest, target } : rest;
|
||||
return target || workflowSettings().run.defaultTarget ? { ...rest, target } : rest;
|
||||
}
|
||||
|
||||
/** A Python configuration on a Docker / Compose target: debugged in its container (`debugInContainer`). */
|
||||
export function containerDebuggable(
|
||||
config: RunConfig,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
targets: readonly RuntimeRunTarget[] = allRunTargets(),
|
||||
): boolean {
|
||||
const target = targetOf(config, targets);
|
||||
return !!target && inContainer(target) && config.debugAdapter === "debugpy";
|
||||
@@ -64,10 +67,8 @@ export function containerDebuggable(
|
||||
* Debugging on run targets isn't supported, except Python in containers: tells so
|
||||
* (offering Run) and returns true when `config` can't be debugged where it runs.
|
||||
*/
|
||||
export function remoteDebugBlocked(
|
||||
config: RunConfig,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
): boolean {
|
||||
export function remoteDebugBlocked(config: RunConfig, targets: readonly RuntimeRunTarget[] = allRunTargets()): boolean {
|
||||
config = withRunTarget(config);
|
||||
if (!config.target || containerDebuggable(config, targets)) return false;
|
||||
const target = targetName(config, targets) ?? config.target;
|
||||
const container = targetOf(config, targets);
|
||||
@@ -96,7 +97,7 @@ export function remoteDebugBlocked(
|
||||
*/
|
||||
export function containerExecutorBlocked(
|
||||
config: RunConfig,
|
||||
targets: readonly RunTargetValid[] = workflowSettings().runTargets,
|
||||
targets: readonly RuntimeRunTarget[] = allRunTargets(),
|
||||
): boolean {
|
||||
const target = targetOf(config, targets);
|
||||
if (!target || !inContainer(target)) return false;
|
||||
@@ -132,7 +133,7 @@ export interface RemedyDeps {
|
||||
askSecret: (message: string, save: boolean) => Promise<{ secret: string; save: boolean } | null>;
|
||||
trustHost: (sshConfig: string) => Promise<unknown>;
|
||||
setSecret: (sshConfig: string, secret: string, save: boolean) => Promise<unknown>;
|
||||
targets: () => readonly RunTargetValid[];
|
||||
targets: () => readonly RuntimeRunTarget[];
|
||||
sshConfigs: () => readonly SshConfigValid[];
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ const defaultDeps: RemedyDeps = {
|
||||
askSecret: (message, save) => promptSecret(message, save),
|
||||
trustHost: (id) => call(commands.sshTrustHost(id)),
|
||||
setSecret: (id, secret, save) => commands.sshSetSecret(id, secret, save),
|
||||
targets: () => workflowSettings().runTargets,
|
||||
targets: () => allRunTargets(),
|
||||
sshConfigs: () => workflowSettings().ssh.configs,
|
||||
};
|
||||
|
||||
|
||||
@@ -13,9 +13,11 @@ vi.mock("@/platform/ipc", () => ({
|
||||
sdkLocateTools: async () => ({ compileDir: "/tmp/run", tools: [] }),
|
||||
},
|
||||
}));
|
||||
import { useProject } from "@/platform/project";
|
||||
import { clearRuntimeCache, rootMarkers, toolEnv } from "./runtimes";
|
||||
|
||||
beforeEach(() => {
|
||||
useProject.setState({ settings: null });
|
||||
entries.clear();
|
||||
pythonNear.mockReset().mockResolvedValue("/env/python");
|
||||
clearRuntimeCache();
|
||||
@@ -41,3 +43,14 @@ it("the production Python runtime query includes the source directory", async ()
|
||||
expect(pythonNear).toHaveBeenCalledWith("/repo/apps/python/src");
|
||||
expect(env.python).toBe("/env/python");
|
||||
});
|
||||
|
||||
it("target PHP and Node runs do not require locally installed interpreters", async () => {
|
||||
useProject.setState({
|
||||
settings: { languages: { php: { runTarget: "plugin-target:php" }, node: { runTarget: "plugin-target:node" } } },
|
||||
});
|
||||
const env = await toolEnv(["php", "node", "npx", "tsx"], "/repo/main.php", "/repo", false, true);
|
||||
expect(env.php).toBe("php");
|
||||
expect(env.tool("node")).toBeUndefined();
|
||||
expect(env.tool("npx")).toBeUndefined();
|
||||
expect(env.tool("tsx")).toBeUndefined();
|
||||
});
|
||||
@@ -4,6 +4,7 @@
|
||||
* minute per directory. Without that command (an older backend) Node.js and
|
||||
* Rust come from SDK discovery and everything else resolves at launch.
|
||||
*/
|
||||
import { withRunTarget } from "@/platform/runTargetSelection";
|
||||
import { call, commands, isTauri } from "@/platform/ipc";
|
||||
import { isWindows } from "./jvmTypes";
|
||||
import type { LocatedTool, ToolEnv } from "./producers";
|
||||
@@ -121,10 +122,23 @@ export async function toolEnv(
|
||||
python: boolean,
|
||||
php = false,
|
||||
): Promise<ToolEnv> {
|
||||
const targetFor = (command: string) =>
|
||||
withRunTarget({ command, kind: command } as import("@/bindings").RunConfig).target;
|
||||
const targetTools = new Set(
|
||||
names.filter(
|
||||
(n) =>
|
||||
["php", "node", "npm", "npx", "pnpm", "yarn", "bun", "tsx", "ts-node"].includes(n) &&
|
||||
targetFor(n === "tsx" || n === "ts-node" ? "node" : n),
|
||||
),
|
||||
);
|
||||
const phpTarget = php && targetFor("php");
|
||||
const [tools, py, phpInterpreter, markers] = await Promise.all([
|
||||
locateTools(names, file),
|
||||
locateTools(
|
||||
names.filter((n) => !targetTools.has(n)),
|
||||
file,
|
||||
),
|
||||
python ? projectPython(file) : Promise.resolve(null),
|
||||
php ? projectPhp() : Promise.resolve(null),
|
||||
phpTarget ? Promise.resolve("php") : php ? projectPhp() : Promise.resolve(null),
|
||||
names.includes("deno") || names.includes("bun")
|
||||
? rootMarkers(root, file)
|
||||
: Promise.resolve({ deno: false, bun: false }),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* (one Run tool window tab each). Output streams through a Channel into a
|
||||
* per-session `ConsoleModel`, batched per animation frame.
|
||||
*/
|
||||
import { withRunTarget } from "@/platform/runTargetSelection";
|
||||
import { create } from "zustand";
|
||||
import { Channel } from "@tauri-apps/api/core";
|
||||
import {
|
||||
@@ -724,6 +725,7 @@ export async function startRun(
|
||||
chain?: readonly string[];
|
||||
} = {},
|
||||
): Promise<RunSession | null> {
|
||||
config = withRunTarget(config);
|
||||
if (!options.launch && isCMakeBuild(config)) {
|
||||
await buildCMake(config.id, options.show !== false);
|
||||
return null;
|
||||
|
||||
@@ -78,6 +78,7 @@ describe("languages settings", () => {
|
||||
|
||||
it("defaults the PHP language level to Auto and keeps only known levels", () => {
|
||||
expect(validateSettings({}).languages.php).toEqual({
|
||||
runTarget: "",
|
||||
interpreter: "",
|
||||
languageLevel: "",
|
||||
includePaths: [],
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Build Tools › Maven: the toolchain each language's server and run configurations
|
||||
* use (applied by `ide-sdk` when language servers start and when run configurations load).
|
||||
*/
|
||||
import { useRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { useEffect, useId, useMemo, useState } from "react";
|
||||
import { call, commands, type Sdk } from "@/platform/ipc";
|
||||
import { IconButton, Input, type SelectOption, T } from "@/ui";
|
||||
@@ -73,6 +75,23 @@ function SdkRow({
|
||||
// ---------------------------------------------------------------------------
|
||||
// Node.js
|
||||
|
||||
function RunTargetRow({ language }: { language: "php" | "node" }) {
|
||||
const [target, setTarget] = useSetting<string>(`languages.${language}.runTarget`);
|
||||
const targets = useRunTargets();
|
||||
const options = [
|
||||
{ value: "", label: "Default run target" },
|
||||
{ value: "local", label: "Local machine" },
|
||||
...targets.map((t) => ({ value: t.id, label: tx`Run in target ${t.name}` })),
|
||||
];
|
||||
if (target && target !== "local" && !targets.some((t) => t.id === target))
|
||||
options.push({ value: target, label: tx`Run in target ${target}` });
|
||||
return (
|
||||
<Row label="Run in target">
|
||||
<Select value={target ?? ""} options={options} onChange={setTarget} aria-label="Run in target" />
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
||||
export function NodePage() {
|
||||
const [pm, setPm] = useSetting<string>("languages.node.packageManager");
|
||||
const { list } = useDetected("packageManager");
|
||||
@@ -103,6 +122,7 @@ export function NodePage() {
|
||||
aria-label="Node interpreter"
|
||||
hint="Runs npm scripts and Node-based language servers (vtsls, eslint, pyright…)."
|
||||
/>
|
||||
<RunTargetRow language="node" />
|
||||
<Row label="Package manager" hint="Used by the npm run configurations detected from package.json scripts.">
|
||||
<Select value={pm} options={pmOptions} onChange={setPm} aria-label="Package manager" />
|
||||
</Row>
|
||||
@@ -212,6 +232,7 @@ export function PhpPage() {
|
||||
/>
|
||||
</Section>
|
||||
<Section title="CLI Interpreter">
|
||||
<RunTargetRow language="php" />
|
||||
<SdkRow
|
||||
k="languages.php.interpreter"
|
||||
label="PHP interpreter"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* containers run configurations can run on (`RunConfig.target`). Consumed by
|
||||
* `ide-run`, `ide-remote` and the run feature.
|
||||
*/
|
||||
import { usePluginRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { useCallback, useEffect, useId, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import { call, commands, isTauri, type DockerConnection, type RemoteEntry } from "@/platform/ipc";
|
||||
@@ -414,8 +415,17 @@ function ContainerFields({ target, update }: { target: RunTargetValid; update: (
|
||||
}
|
||||
|
||||
function RunTargetsEditor() {
|
||||
const plugins = usePluginRunTargets((s) => s.targets);
|
||||
const [defaultTarget, setDefaultTarget] = useSetting<string>("run.defaultTarget");
|
||||
const [raw, setTargets] = useSetting<RunTargetValid[] | undefined>("runTargets");
|
||||
const targets = raw ?? [];
|
||||
const allTargets = [...targets, ...plugins.map((t) => ({ id: t.id, name: `${t.target.name} (${t.pluginName})` }))];
|
||||
const defaultOptions: SelectOption[] = [
|
||||
{ value: "", label: "Local machine" },
|
||||
...allTargets.map((t) => ({ value: t.id, label: t.name })),
|
||||
];
|
||||
if (defaultTarget && !allTargets.some((t) => t.id === defaultTarget))
|
||||
defaultOptions.push({ value: defaultTarget, label: tx`${defaultTarget} (missing)` });
|
||||
const sshConfigs = useSshConfigs();
|
||||
const [selected, setSelected] = useState<string | null>(targets[0]?.id ?? null);
|
||||
const current = targets.find((t) => t.id === selected) ?? null;
|
||||
@@ -478,11 +488,19 @@ function RunTargetsEditor() {
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.toolList} role="listbox" aria-label={tx("Run targets")}>
|
||||
{targets.length === 0 && (
|
||||
{targets.length === 0 && plugins.length === 0 && (
|
||||
<div className={clsx(styles.toolRow, styles.empty)}>
|
||||
<T>No run targets. Click + to add one.</T>
|
||||
</div>
|
||||
)}
|
||||
{plugins.map((t) => (
|
||||
<div key={t.id} className={styles.toolRow} role="option" aria-selected={false}>
|
||||
<span className={styles.toolName}>{t.target.name}</span>
|
||||
<span className={styles.toolGroup}>
|
||||
{t.pluginName} · <T>Read-only</T>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{targets.map((t) => (
|
||||
<div
|
||||
key={t.id}
|
||||
@@ -504,6 +522,16 @@ function RunTargetsEditor() {
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<Section>
|
||||
<Row label="Default run target">
|
||||
<Select
|
||||
value={defaultTarget ?? ""}
|
||||
onChange={setDefaultTarget}
|
||||
aria-label="Default run target"
|
||||
options={defaultOptions}
|
||||
/>
|
||||
</Row>
|
||||
</Section>
|
||||
{current && (
|
||||
<Section title="Target Settings">
|
||||
<TextField label="Name" value={current.name} onChange={(name) => update({ name })} />
|
||||
|
||||
@@ -132,8 +132,9 @@ export interface ArtifactConfigValid {
|
||||
export interface LanguagesValid {
|
||||
python: { interpreter: string; activateVirtualenv: boolean };
|
||||
ruby: { interpreter: string };
|
||||
node: { interpreter: string; packageManager: "" | "npm" | "pnpm" | "yarn" | "bun" };
|
||||
node: { runTarget: string; interpreter: string; packageManager: "" | "npm" | "pnpm" | "yarn" | "bun" };
|
||||
php: {
|
||||
runTarget: string;
|
||||
interpreter: string;
|
||||
languageLevel: (typeof PHP_LANGUAGE_LEVELS)[number];
|
||||
includePaths: string[];
|
||||
@@ -227,8 +228,8 @@ export type FolderListKey =
|
||||
export const DEFAULT_LANGUAGES: LanguagesValid = {
|
||||
python: { interpreter: "", activateVirtualenv: true },
|
||||
ruby: { interpreter: "" },
|
||||
node: { interpreter: "", packageManager: "" },
|
||||
php: { interpreter: "", languageLevel: "", includePaths: [], stubs: [], phpstanConfig: "" },
|
||||
node: { runTarget: "", interpreter: "", packageManager: "" },
|
||||
php: { runTarget: "", interpreter: "", languageLevel: "", includePaths: [], stubs: [], phpstanConfig: "" },
|
||||
rust: { toolchain: "", stdlib: "", checkOnSave: true, checkCommand: "check", rustfmtArgs: "" },
|
||||
go: { goroot: "", gopath: "", buildTags: DEFAULT_GO_BUILD_TAGS, modules: { env: {}, autoVendor: true } },
|
||||
typescript: { version: "bundled" },
|
||||
@@ -350,10 +351,12 @@ export function validateLanguages(raw: unknown): LanguagesValid {
|
||||
},
|
||||
ruby: { interpreter: text(ruby.interpreter, d.ruby.interpreter) },
|
||||
node: {
|
||||
runTarget: text(node.runTarget, ""),
|
||||
interpreter: text(node.interpreter, d.node.interpreter),
|
||||
packageManager: oneOf(node.packageManager, ["", "npm", "pnpm", "yarn", "bun"] as const, d.node.packageManager),
|
||||
},
|
||||
php: {
|
||||
runTarget: text(php.runTarget, ""),
|
||||
interpreter: text(php.interpreter, d.php.interpreter),
|
||||
languageLevel: oneOf(php.languageLevel, PHP_LANGUAGE_LEVELS, d.php.languageLevel),
|
||||
includePaths: strings(php.includePaths),
|
||||
|
||||
@@ -578,5 +578,12 @@
|
||||
"Open Plugin Terminal Session": "Open Plugin Terminal Session",
|
||||
"Debug Plugin Configuration": "Debug Plugin Configuration",
|
||||
"Expected: {0}": "Expected: {0}",
|
||||
"Actual: {0}": "Actual: {0}"
|
||||
"Actual: {0}": "Actual: {0}",
|
||||
"Use {0} for running PHP / Node / Composer in this project?": "Use {0} for running PHP / Node / Composer in this project?",
|
||||
"Use": "Use",
|
||||
"Not now": "Not now",
|
||||
"Run in target": "Run in target",
|
||||
"Run in target {0}": "Run in target {0}",
|
||||
"Default run target": "Default run target",
|
||||
"Read-only": "Read-only"
|
||||
}
|
||||
@@ -6921,5 +6921,11 @@
|
||||
"Open Plugin Terminal Session": "打开插件终端会话",
|
||||
"Debug Plugin Configuration": "调试插件配置",
|
||||
"Expected: {0}": "期望值:{0}",
|
||||
"Actual: {0}": "实际值:{0}"
|
||||
"Actual: {0}": "实际值:{0}",
|
||||
"Use {0} for running PHP / Node / Composer in this project?": "在此项目中使用 {0} 运行 PHP / Node / Composer?",
|
||||
"Use": "使用",
|
||||
"Not now": "暂不使用",
|
||||
"Run in target": "在目标中运行",
|
||||
"Run in target {0}": "在目标 {0} 中运行",
|
||||
"Default run target": "默认运行目标"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/** Host-owned registrations shared by plugins, Run and Settings. */
|
||||
import { create } from "zustand";
|
||||
import { useMemo } from "react";
|
||||
import type { RegisteredRunTarget } from "@/bindings";
|
||||
import { DEFAULT_RUN_TARGET, type RunTargetValid } from "./remoteSettings";
|
||||
import { useWorkflowSettings, workflowSettings } from "./workflowSettings";
|
||||
|
||||
export const usePluginRunTargets = create<{ targets: RegisteredRunTarget[] }>(() => ({ targets: [] }));
|
||||
export type RuntimeRunTarget = Omit<RunTargetValid, "kind"> & { kind: RunTargetValid["kind"] | "plugin" };
|
||||
const converted = (targets: RegisteredRunTarget[]): RuntimeRunTarget[] =>
|
||||
targets.map((t) => ({
|
||||
...DEFAULT_RUN_TARGET,
|
||||
kind: "plugin",
|
||||
id: t.id,
|
||||
name: `${t.target.name} (${t.pluginName})`,
|
||||
}));
|
||||
export function runTargets(): RuntimeRunTarget[] {
|
||||
return [...workflowSettings().runTargets, ...converted(usePluginRunTargets.getState().targets)];
|
||||
}
|
||||
export function useRunTargets(): RuntimeRunTarget[] {
|
||||
const saved = useWorkflowSettings((s) => s.runTargets);
|
||||
const plugins = usePluginRunTargets((s) => s.targets);
|
||||
return useMemo(() => [...saved, ...converted(plugins)], [saved, plugins]);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ let seq = 0;
|
||||
export const newRemoteId = (prefix: string) => `${prefix}-${Date.now().toString(36)}-${++seq}`;
|
||||
|
||||
/** Whether `target` runs configurations in a container (Docker, Compose) rather than over SSH. */
|
||||
export const inContainer = (target: Pick<RunTargetValid, "kind">) => target.kind !== "ssh";
|
||||
export const inContainer = (target: { kind: string }) => target.kind === "docker" || target.kind === "compose";
|
||||
|
||||
/** Backend connection descriptor for deployment and folder browsing. */
|
||||
export function deploymentConnection(server: DeploymentServerValid): { kind: "local" } | { kind: "sftp"; ssh: string } {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
@@ -95,6 +95,7 @@ export interface DebuggerSettingsValid {
|
||||
}
|
||||
|
||||
export interface RunSettingsValid {
|
||||
defaultTarget: string;
|
||||
confirmRerun: boolean;
|
||||
confirmTerminate: boolean;
|
||||
showOnStart: boolean;
|
||||
@@ -256,7 +257,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
|
||||
skipLibraryCode: true,
|
||||
python: { attachSubprocess: true, gevent: false },
|
||||
},
|
||||
run: { confirmRerun: true, confirmTerminate: true, showOnStart: true, terminationTimeoutMs: 3000 },
|
||||
run: { defaultTarget: "", confirmRerun: true, confirmTerminate: true, showOnStart: true, terminationTimeoutMs: 3000 },
|
||||
terminal: {
|
||||
startDirectory: "",
|
||||
env: {},
|
||||
@@ -403,6 +404,7 @@ export function validateRun(raw: unknown): RunSettingsValid {
|
||||
const d = DEFAULT_WORKFLOW.run;
|
||||
const v = obj(raw);
|
||||
return {
|
||||
defaultTarget: text(v.defaultTarget, ""),
|
||||
confirmRerun: bool(v.confirmRerun, d.confirmRerun),
|
||||
confirmTerminate: bool(v.confirmTerminate, d.confirmTerminate),
|
||||
showOnStart: bool(v.showOnStart, d.showOnStart),
|
||||
|
||||
Reference in new issue
Заблокувати користувача