Compare commits

...
Author SHA1 Message Date
l0ng-ai 96eea4704d fix(run): show before-launch tasks as ordered tags 2026-11-23 02:59:59 +08:00
5 changed files with 228 additions and 89 deletions

No files matched your search

+73 -30
View File
@@ -1,39 +1,82 @@
import type { Page } from "@playwright/test";
import type { BeforeLaunchTask } from "../src/bindings";
import { expect, test } from "./fixtures";
async function openConfigurations(page: Page, target?: string) {
await page.evaluate(async (target) => {
const path = "/src/features/run/store.ts";
const { useRun } = await import(/* @vite-ignore */ path);
const base = {
kind: "shell",
command: "/Users/developer/projects/acme/services/payments/scripts/start-development-server",
args: ["--watch"],
cwd: "/Users/developer/projects/acme/services/payments",
env: { NODE_ENV: "development" },
detected: false,
isTest: false,
debugAdapter: null,
};
useRun.setState({
configs: [
{
...base,
id: "layout:app",
name: "Payments development server",
target,
beforeLaunch: [{ kind: "run", target: "layout:prepare" }],
},
{ ...base, id: "layout:prepare", name: "Prepare generated sources for the payments development server" },
],
selectedId: "layout:app",
loaded: true,
editorOpen: true,
});
}, target);
async function openConfigurations(page: Page, target?: string, beforeLaunch?: BeforeLaunchTask[]) {
await page.evaluate(
async ({ target, beforeLaunch }) => {
const path = "/src/features/run/store.ts";
const { useRun } = await import(/* @vite-ignore */ path);
const base = {
kind: "shell",
command: "/Users/developer/projects/acme/services/payments/scripts/start-development-server",
args: ["--watch"],
cwd: "/Users/developer/projects/acme/services/payments",
env: { NODE_ENV: "development" },
detected: false,
isTest: false,
debugAdapter: null,
};
useRun.setState({
configs: [
{
...base,
id: "layout:app",
name: "Payments development server",
target,
beforeLaunch: beforeLaunch ?? [{ kind: "run", target: "layout:prepare" }],
},
{ ...base, id: "layout:prepare", name: "Prepare generated sources for the payments development server" },
],
selectedId: "layout:app",
loaded: true,
editorOpen: true,
});
},
{ target, beforeLaunch },
);
await expect(page.getByRole("dialog", { name: "Run/Debug Configurations", exact: true })).toBeVisible();
}
test("before-launch tasks wrap as ordered tags and keep their edit controls", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1150, height: 820 });
await openConfigurations(page, undefined, [
{ kind: "build" },
{ kind: "buildArtifacts" },
{ kind: "command", target: "make generate" },
]);
const dialog = page.getByRole("dialog", { name: "Run/Debug Configurations", exact: true });
const tasks = dialog.getByRole("list", { name: "Before launch tasks", exact: true });
const build = tasks.getByRole("button", { name: "1. Build Project", exact: true });
const artifacts = tasks.getByRole("button", { name: "2. Build Artifacts", exact: true });
await tasks.scrollIntoViewIfNeeded();
await expect(build).toBeVisible();
expect((await build.boundingBox())!.y).toBeCloseTo((await artifacts.boundingBox())!.y, 0);
await expect(build).toHaveCSS("font-size", "13px");
await page.setViewportSize({ width: 520, height: 820 });
await expect.poll(() => tasks.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
const command = tasks.getByRole("textbox", { name: "Before launch command 3" });
expect((await command.boundingBox())!.y).toBeGreaterThan((await build.boundingBox())!.y + 20);
await command.fill("make report");
await build.press("Enter");
const actions = page.getByRole("menu", { name: "Task Actions", exact: true });
const moveDown = actions.getByRole("menuitem", { name: "Move Down", exact: true });
await expect(moveDown).toBeVisible();
await moveDown.click();
await expect(tasks.getByRole("button", { name: "1. Build Artifacts", exact: true })).toBeVisible();
const moved = tasks.getByRole("listitem").filter({
has: page.getByRole("button", { name: "2. Build Project", exact: true }),
});
await moved.getByRole("button", { name: "Remove Task" }).click();
await expect(tasks.getByRole("textbox", { name: "Before launch command 2" })).toHaveValue("make report");
await tasks.getByRole("button", { name: "Add task", exact: true }).click();
await page.getByRole("menuitem", { name: "Build Project", exact: true }).click();
await expect(tasks.getByRole("button", { name: "3. Build Project", exact: true })).toBeVisible();
});
test("long run target names leave room for configuration names in the sidebar", async ({ workbench: page }) => {
const target = "payments-development-shared-staging-runner-west";
await openConfigurations(page, target);
+118 -57
View File
@@ -6,7 +6,16 @@
import { writeClipboardText } from "@/platform/clipboard";
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 {
useEffect,
useMemo,
useRef,
useState,
type KeyboardEvent,
type MouseEvent,
type ReactNode,
type RefObject,
} from "react";
import clsx from "clsx";
import { isTauri, type BeforeLaunchTask, type BuildPolicy, type RunConfig } from "@/platform/ipc";
import { useWorkflowSettings } from "@/platform/workflowSettings";
@@ -54,6 +63,16 @@ import { TomcatSettings } from "./TomcatSettings";
import { toolWindowTitle } from "@/workbench/toolwindows/title";
import styles from "./Run.module.css";
const TASK_ICONS: Readonly<Partial<Record<string, string>>> = {
build: "build-project",
buildModule: "build-project",
buildArtifacts: "build-rebuild",
dotnetBuild: "build-project",
run: "run",
tool: "settings",
command: "terminal",
};
/**
* Debug adapters with a real launch template (`debugger/launch.ts`, `debugger/java.ts`),
* verified against small programs. Others (dart, …) only got
@@ -332,7 +351,7 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
const [envOpen, setEnvOpen] = useState(false);
const [modifyOpen, setModifyOpen] = useState(false);
const [lastRequest, setLastRequest] = useState(modifyRequest);
const [taskMenu, setTaskMenu] = useState(false);
const [taskMenu, setTaskMenu] = useState<"add" | { index: number; anchor: HTMLButtonElement } | null>(null);
const modifyRef = useRef<HTMLButtonElement>(null);
const taskRef = useRef<HTMLButtonElement>(null);
@@ -406,23 +425,23 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
run: () => addTask("run", c.id),
})),
},
{ label: TASK_LABELS.build, icon: "build-project", run: () => addTask("build") },
{ label: TASK_LABELS.build, icon: TASK_ICONS.build, run: () => addTask("build") },
{
label: TASK_LABELS.buildModule,
icon: "build-project",
icon: TASK_ICONS.buildModule,
disabled: config.module == null,
run: () => addTask("buildModule", config.module ?? ""),
},
{ label: TASK_LABELS.buildArtifacts, icon: "build-rebuild", run: () => addTask("buildArtifacts") },
{ label: TASK_LABELS.buildArtifacts, icon: TASK_ICONS.buildArtifacts, run: () => addTask("buildArtifacts") },
...(config.kind === "dotnet"
? [{ label: TASK_LABELS.dotnetBuild, icon: "build-project", run: () => addTask("dotnetBuild") }]
? [{ label: TASK_LABELS.dotnetBuild, icon: TASK_ICONS.dotnetBuild, run: () => addTask("dotnetBuild") }]
: []),
{
label: TASK_LABELS.tool,
disabled: !externalTools.length,
submenu: externalTools.map((t) => ({ label: t.name, verbatim: true, run: () => addTask("tool", t.id) })),
},
{ label: TASK_LABELS.command, icon: "terminal", run: () => addTask("command") },
{ label: TASK_LABELS.command, icon: TASK_ICONS.command, run: () => addTask("command") },
{
label: TASK_LABELS.toolWindow,
submenu: [...toolWindows.values()]
@@ -442,6 +461,7 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
[next[i], next[j]] = [next[j]!, next[i]!];
setTasks(next);
};
const taskActions = taskMenu === "add" ? null : taskMenu;
const adapterOptions: SelectOption[] = [
{ value: "", label: "None" },
@@ -763,62 +783,103 @@ export function ConfigForm({ config, all, type, errors, template, onChange, modi
{isShown("beforeLaunch") && (
<Field label="Before launch" error={errors.beforeLaunch} top>
<div className={styles.taskList} role="list" aria-label={tx("Before launch tasks")}>
{tasks.map((t, i) => (
<div key={i} role="listitem" className={styles.taskRow}>
{t.kind === "command" ? (
<Input
mono
aria-label={txTemplate(`Before launch command ${i + 1}`)}
value={t.target ?? ""}
placeholder="Shell command, e.g. make generate"
onChange={(e) =>
setTasks(tasks.map((x, j) => (j === i ? { ...x, target: e.target.value } : x)))
}
/>
) : (
<span className={styles.taskLabel} title={txTemplate(taskLabel(t, all))}>
{txTemplate(taskLabel(t, all))}
</span>
)}
<span className={styles.taskActions}>
<div className={styles.beforeLaunchTasks} role="list" aria-label={tx("Before launch tasks")}>
{tasks.map((t, i) => {
const label = txTemplate(taskLabel(t, all));
const target = t.kind === "run" ? all.find((c) => c.id === t.target) : undefined;
const icon = target ? configIcon(target) : TASK_ICONS[t.kind];
const prefix = (
<>
{icon && <Icon name={icon} size={14} />}
<span className={styles.taskOrder}>{i + 1}.</span>
</>
);
const actions = {
"aria-haspopup": "menu" as const,
"aria-expanded": taskActions?.index === i,
onClick: (e: MouseEvent<HTMLButtonElement>) => setTaskMenu({ index: i, anchor: e.currentTarget }),
};
return (
<div key={i} role="listitem" className={styles.taskTag}>
{t.kind === "command" ? (
<>
{prefix}
<Input
mono
className={styles.taskCommand}
aria-label={txTemplate(`Before launch command ${i + 1}`)}
value={t.target ?? ""}
placeholder="Shell command, e.g. make generate"
onChange={(e) =>
setTasks(tasks.map((x, j) => (j === i ? { ...x, target: e.target.value } : x)))
}
/>
<IconButton icon="more" title="Task Actions" size="small" {...actions} />
</>
) : (
<button type="button" className={styles.taskName} title={label} {...actions}>
{prefix}
<span className={styles.taskLabel}>{label}</span>
</button>
)}
<IconButton
icon="arrow-up"
size="small"
iconSize={12}
title="Move Up"
disabled={i === 0}
onClick={() => moveTask(i, -1)}
/>
<IconButton
icon="arrow-down"
size="small"
iconSize={12}
title="Move Down"
disabled={i === tasks.length - 1}
onClick={() => moveTask(i, 1)}
/>
<IconButton
icon="minus"
icon="close"
size="small"
iconSize={12}
title="Remove Task"
onClick={() => setTasks(tasks.filter((_, j) => j !== i))}
/>
</span>
</div>
))}
<Button
ref={taskRef}
size="small"
variant="ghost"
icon="plus"
aria-haspopup="menu"
onClick={() => setTaskMenu(true)}
>
<T>Add task</T>
</Button>
<Menu open={taskMenu} anchor={taskRef} items={taskItems} onClose={() => setTaskMenu(false)} />
</div>
);
})}
<div role="listitem">
{tasks.length ? (
<IconButton
ref={taskRef}
title="Add task"
icon="plus"
size="small"
aria-haspopup="menu"
aria-expanded={taskMenu === "add"}
onClick={() => setTaskMenu("add")}
/>
) : (
<Button
ref={taskRef}
size="small"
variant="ghost"
icon="plus"
aria-haspopup="menu"
aria-expanded={taskMenu === "add"}
onClick={() => setTaskMenu("add")}
>
<T>Add task</T>
</Button>
)}
</div>
<Menu open={taskMenu === "add"} anchor={taskRef} items={taskItems} onClose={() => setTaskMenu(null)} />
{taskActions && (
<Menu
open
anchor={taskActions.anchor}
aria-label={tx("Task Actions")}
items={[
{
label: "Move Up",
icon: "arrow-up",
disabled: taskActions.index === 0,
run: () => moveTask(taskActions.index, -1),
},
{
label: "Move Down",
icon: "arrow-down",
disabled: taskActions.index === tasks.length - 1,
run: () => moveTask(taskActions.index, 1),
},
]}
onClose={() => setTaskMenu(null)}
/>
)}
</div>
</Field>
)}
+35 -2
View File
@@ -958,10 +958,43 @@
.taskRow > :first-child {
min-width: 0;
}
.taskActions {
.beforeLaunchTasks {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-1);
}
.taskTag {
display: inline-flex;
align-items: center;
gap: var(--space-0-5);
gap: var(--space-1);
min-width: 0;
max-width: 100%;
min-height: var(--h-list-row);
padding-inline: var(--space-2) var(--space-1);
border-radius: var(--radius-small);
background: var(--bg-elev);
color: var(--fg);
font-size: var(--fs-ui);
}
.taskName {
display: inline-flex;
align-items: center;
gap: var(--space-1);
min-width: 0;
min-height: var(--h-list-row);
text-align: start;
}
.taskName:hover {
color: var(--fg-strong);
}
.taskOrder {
flex: none;
color: var(--fg-muted);
}
.taskTag .taskCommand {
width: 24ch;
height: var(--h-control-small);
}
.taskLabel {
overflow: hidden;
+1
View File
@@ -1,4 +1,5 @@
{
"Task Actions": "Task Actions",
"Search commits": "Search commits",
"Amend commit failed": "Amend commit failed",
"Amending this commit would cause a conflict. You can keep the prepared changes as a separate amend commit.": "Amending this commit would cause a conflict. You can keep the prepared changes as a separate amend commit.",
+1
View File
@@ -4253,6 +4253,7 @@
"File relative to the project root": "相对于项目根目录的文件",
"Shell command, e.g. make generate": "Shell 命令,例如 make generate",
"Remove Task": "移除任务",
"Task Actions": "任务操作",
"Add task": "添加任务",
"Add configuration…": "添加配置…",
"Add configuration": "添加配置",