diff --git a/e2e/runConfigLayout.spec.ts b/e2e/runConfigLayout.spec.ts index 9afb50c80..6454c927d 100644 --- a/e2e/runConfigLayout.spec.ts +++ b/e2e/runConfigLayout.spec.ts @@ -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); diff --git a/src/features/run/ConfigForm.tsx b/src/features/run/ConfigForm.tsx index a9e7a20c3..40c5c6354 100644 --- a/src/features/run/ConfigForm.tsx +++ b/src/features/run/ConfigForm.tsx @@ -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>> = { + 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(null); const taskRef = useRef(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") && ( -
- {tasks.map((t, i) => ( -
- {t.kind === "command" ? ( - - setTasks(tasks.map((x, j) => (j === i ? { ...x, target: e.target.value } : x))) - } - /> - ) : ( - - {txTemplate(taskLabel(t, all))} - - )} - +
+ {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 && } + {i + 1}. + + ); + const actions = { + "aria-haspopup": "menu" as const, + "aria-expanded": taskActions?.index === i, + onClick: (e: MouseEvent) => setTaskMenu({ index: i, anchor: e.currentTarget }), + }; + return ( +
+ {t.kind === "command" ? ( + <> + {prefix} + + setTasks(tasks.map((x, j) => (j === i ? { ...x, target: e.target.value } : x))) + } + /> + + + ) : ( + + )} moveTask(i, -1)} - /> - moveTask(i, 1)} - /> - setTasks(tasks.filter((_, j) => j !== i))} /> - -
- ))} - - setTaskMenu(false)} /> +
+ ); + })} +
+ {tasks.length ? ( + setTaskMenu("add")} + /> + ) : ( + + )} +
+ setTaskMenu(null)} /> + {taskActions && ( + moveTask(taskActions.index, -1), + }, + { + label: "Move Down", + icon: "arrow-down", + disabled: taskActions.index === tasks.length - 1, + run: () => moveTask(taskActions.index, 1), + }, + ]} + onClose={() => setTaskMenu(null)} + /> + )}
)} diff --git a/src/features/run/Run.module.css b/src/features/run/Run.module.css index bf1783cb3..0f57b58cb 100644 --- a/src/features/run/Run.module.css +++ b/src/features/run/Run.module.css @@ -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; diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index eb1d53264..3a0b392a8 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -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.", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index fcc3bf023..9e89c9a0c 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -4257,6 +4257,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": "添加配置",