From 6648f502f18bce88277b5864fa3518ea76e1daf3 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 2 Dec 2026 18:25:48 +0800 Subject: [PATCH] feat(services): list Spring Boot configurations by default and show their address (#7508) Projects without a saved Services list show Spring Boot run configurations by default; a saved list stays authoritative. Running Spring Boot nodes show the port and announced context path for runs and debug sessions. Fixes #7346 --- e2e/services.spec.ts | 91 +++++++++++++------ src/features/run/services.test.ts | 33 +++++-- src/features/run/services.tsx | 56 +++++++----- .../services/ServicesTree.debug.test.tsx | 2 +- 4 files changed, 120 insertions(+), 62 deletions(-) diff --git a/e2e/services.spec.ts b/e2e/services.spec.ts index cbc13b9194..29142f69d1 100644 --- a/e2e/services.spec.ts +++ b/e2e/services.spec.ts @@ -2,34 +2,39 @@ import type { Page } from "@playwright/test"; import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; /** Supply detected configurations without launching desktop processes. */ -async function configure(page: Page, extra = 0) { - await page.evaluate(async (extra) => { - const storePath = "/src/features/run/store.ts"; - const projectPath = "/src/platform/project.ts"; - const { useRun } = await import(storePath); - const { useProject } = await import(projectPath); - localStorage.setItem(`openidea.services.runTypes:${useProject.getState().project.root}`, '["spring-boot","npm"]'); - useRun.setState({ - configs: [ - ["gateway", "spring-boot"], - ["portal", "spring-boot"], - ["web", "npm"], - ["worker", "npm"], - ...Array.from({ length: extra }, (_, i) => [`app-${i}`, "spring-boot"]), - ].map(([id, kind]) => ({ - id, - name: id, - kind, - command: kind, - args: [], - env: {}, - cwd: null, - detected: true, - isTest: false, - debugAdapter: null, - })), - }); - }, extra); +async function configure(page: Page, extra = 0, useDefaults = false) { + await page.evaluate( + async ({ extra, useDefaults }) => { + const storePath = "/src/features/run/store.ts"; + const projectPath = "/src/platform/project.ts"; + const { useRun } = await import(storePath); + const { useProject } = await import(projectPath); + const key = `openidea.services.runTypes:${useProject.getState().project.root}`; + if (useDefaults) localStorage.removeItem(key); + else localStorage.setItem(key, '["spring-boot","npm"]'); + useRun.setState({ + configs: [ + ["gateway", "spring-boot"], + ["portal", "spring-boot"], + ["web", "npm"], + ["worker", "npm"], + ...Array.from({ length: extra }, (_, i) => [`app-${i}`, "spring-boot"]), + ].map(([id, kind]) => ({ + id, + name: id, + kind, + command: kind, + args: [], + env: {}, + cwd: null, + detected: true, + isTest: false, + debugAdapter: null, + })), + }); + }, + { extra, useDefaults }, + ); if (!(await page.getByRole("tree", { name: "Services", exact: true }).isVisible())) await page.keyboard.press("Meta+8"); await expect(page.getByRole("tree", { name: "Services", exact: true })).toBeVisible(); @@ -48,6 +53,36 @@ async function move(page: Page, source: string, target: string) { await page.mouse.up(); } +test("Services shows Spring Boot run configurations and their running ports by default", async ({ + workbench: page, +}) => { + await configure(page, 0, true); + const tree = page.getByRole("tree", { name: "Services", exact: true }); + await expect(tree.getByRole("treeitem")).toHaveText(["Spring Boot", "gateway", "portal"]); + await page.evaluate(async () => { + const storePath = "/src/features/run/store.ts"; + const { useRun } = (await import(/* @vite-ignore */ storePath)) as typeof import("../src/features/run/store"); + const config = useRun.getState().configs.find((config) => config.id === "gateway")!; + useRun.setState({ + sessions: [ + { + id: "gateway-run", + config, + runId: null, + status: "running", + exitCode: null, + startedAt: Date.now(), + endedAt: null, + stdinClosed: true, + httpPort: 8080, + httpPath: "/api", + }, + ], + }); + }); + await expect(tree.getByRole("treeitem", { name: /gateway/ })).toContainText(":8080/api/"); +}); + test("Services favors details and stacks the panes when docked to the side", async ({ workbench: page }) => { await configure(page); const services = page.getByRole("region", { name: "Services", exact: true }); diff --git a/src/features/run/services.test.ts b/src/features/run/services.test.ts index 2ef33b6319..5680f0030e 100644 --- a/src/features/run/services.test.ts +++ b/src/features/run/services.test.ts @@ -20,6 +20,7 @@ import { registerRunServiceActions, readHidden, readTypes, + removeType, runServiceItems, runningServiceCount, sessionDetail, @@ -142,7 +143,7 @@ describe("run configurations in Services", () => { const attached = runServiceItems([c], [{ ...r, status: "running" }], ["spring-boot"], {}, [{ ...d, processId: 7 }]); expect(attached[0]?.detail).toBe("1 running"); expect(attached[0]?.children).toHaveLength(1); - expect(attached[0]?.children?.[0]?.detail).toBe(":8080"); + expect(attached[0]?.children?.[0]?.detail).toBe(":8080/"); }); it("shows the app port of a direct debug session like for Run", () => { @@ -159,7 +160,7 @@ describe("run configurations in Services", () => { show: () => {}, }; expect(runServiceItems([c], [], ["spring-boot"], {}, [d])[0]?.children?.[0]).toMatchObject({ - detail: ":8080", + detail: ":8080/", icon: "debug", dim: false, }); @@ -279,23 +280,24 @@ describe("run configurations in Services", () => { it("shows the HTTP port of a running application instead of its state", () => { const app = config("spring:app", "spring-boot"); const running = session("s1", app, "running", 1, { httpPort: 8080 }); - expect(sessionDetail(running)).toBe(":8080"); + expect(sessionDetail(running)).toBe(":8080/"); + expect(sessionDetail({ ...running, httpPath: "/api" })).toBe(":8080/api/"); expect(sessionDetail(session("s1", app, "running", 1))).toBe("Running"); expect(sessionDetail(session("s1", app, "finished", 1, { httpPort: 8080, stopped: true }))).toBe("Stopped"); - expect(runServiceItems([app], [running], ["spring-boot"])[0]!.children![0]!.detail).toBe(":8080"); + expect(runServiceItems([app], [running], ["spring-boot"])[0]!.children![0]!.detail).toBe(":8080/"); }); }); describe("types added to Services", () => { beforeEach(() => localStorage.clear()); - it("starts empty and persists the user's list per project", () => { - expect(readTypes("/p")).toEqual([]); + it("includes Spring Boot by default and respects the user's saved list", () => { + expect(readTypes("/p")).toEqual(["spring-boot"]); localStorage.setItem("openidea.services.runTypes:/p", JSON.stringify(["npm"])); expect(readTypes("/p")).toEqual(["npm"]); localStorage.setItem("openidea.services.runTypes:/p", "[]"); expect(readTypes("/p")).toEqual([]); - expect(readTypes("/q")).toEqual([]); + expect(readTypes("/q")).toEqual(["spring-boot"]); }); }); @@ -417,7 +419,8 @@ describe("running service count (the Services badge)", () => { expect(runningServiceCount()).toBeNull(); }); - it("leaves out types not added and Docker kinds, and counts a live debugger", () => { + it("leaves out removed types and Docker kinds, and counts a live debugger", () => { + removeType("spring-boot"); const compose = config("compose", "docker-compose"); useRun.setState({ configs: [dev, app, compose], @@ -438,7 +441,7 @@ describe("running service count (the Services badge)", () => { rerun: null, show: () => {}, }; - // `app` is not added yet: its live debugger does not count. + // The removed type only counts after it is added back. useDebugRunSessions.setState({ serviceSessions: [debugged] }); expect(runningServiceCount()).toBe(1); addType("spring-boot"); @@ -803,6 +806,16 @@ describe("removing a workspace member from Services", () => { expect(ipc.runConfigs).toHaveBeenCalled(); }); + it("keeps Spring Boot enabled by default when its last workspace member is removed", async () => { + useRun.setState({ configs: [{ ...main, cwd: "/w/spring" }], sessions: [] }); + ipc.runConfigs.mockImplementation(async () => ({ status: "ok", data: [] })); + + await cleanupRemovedProject("/w/spring"); + + expect(localStorage.getItem("openidea.services.runTypes:/w/main")).toBeNull(); + expect(readTypes("/w/main")).toEqual(["spring-boot"]); + }); + it("keeps a type another project still uses, and a sibling with a shared prefix", async () => { const other = { ...config("serve", "npm"), cwd: "/w/main" }; const sibling = { ...config("dev2", "npm"), cwd: "/w/vue2" }; @@ -878,6 +891,6 @@ describe("service selection", () => { await pending; await Promise.resolve(); expect(readHidden("/other-selection")).toEqual({}); - expect(readTypes("/other-selection")).toEqual([]); + expect(readTypes("/other-selection")).toEqual(["spring-boot"]); }); }); diff --git a/src/features/run/services.tsx b/src/features/run/services.tsx index fd8ed227a7..71e6b4f7d1 100644 --- a/src/features/run/services.tsx +++ b/src/features/run/services.tsx @@ -1,6 +1,6 @@ /** * Run configurations in the Services tool window (IDEA's Run Dashboard): the - * configuration types added there ("Add Service › Run Configuration Type"), one + * configuration types shown there, one * group each, with run / debug / stop / rerun per configuration. Nothing else is * listed, and what is removed leaves at once; a run it started keeps its console * in the Run tool window. A configuration that ran shows its console in the @@ -97,18 +97,22 @@ const DOCKER_PROVIDER_KINDS: ReadonlySet = new Set(["docker-compose", "d export const useAddedTypes = create<{ root: string | null; types: string[] }>(() => ({ root: null, types: [] })); -/** The project's types; empty until the user adds one with "Add Service". */ -export function readTypes(root: string): string[] { +/** Stored preferences stay authoritative, including an explicitly empty dashboard. */ +function storedTypes(root: string): string[] | null { try { const raw = localStorage.getItem(STORAGE_KEY + root); - if (raw === null) return []; + if (raw === null) return null; const v: unknown = JSON.parse(raw); - return Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []; + return Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : null; } catch { - return []; + return null; } } +export function readTypes(root: string): string[] { + return storedTypes(root) ?? ["spring-boot"]; +} + function addedTypes(root: string | null): string[] { const s = useAddedTypes.getState(); return s.root === root ? s.types : root ? readTypes(root) : []; @@ -163,6 +167,7 @@ function insideRoot(path: string, root: string): boolean { * the added types that would otherwise render empty groups. */ export async function cleanupRemovedProject(removedRoot: string): Promise { + const root = useProject.getState().project?.root; const { configs, sessions, temporary } = useRun.getState(); const ofRemoved = (c: RunConfig) => !!c.cwd && insideRoot(c.cwd, removedRoot); const removedIds = new Set(configs.filter(ofRemoved).map((c) => c.id)); @@ -188,6 +193,7 @@ export async function cleanupRemovedProject(removedRoot: string): Promise const kinds = new Set(configs.filter(ofRemoved).map((c) => c.kind)); await loadConfigs(); + if (!root || root !== useProject.getState().project?.root || storedTypes(root) === null) return; const { configs: fresh, sessions: liveSessions } = useRun.getState(); const liveKinds = new Set([...fresh.map((c) => c.kind), ...liveSessions.map((s) => s.config.kind)]); for (const kind of kinds) if (!liveKinds.has(kind)) removeType(kind); @@ -314,9 +320,13 @@ export function sessionStatus(s: RunSession | undefined): string | undefined { return "Finished"; } -/** A node's grey text: the HTTP port of a running web application, else the state. */ +function portDetail(config: RunConfig, port: number, path?: string): string { + return config.kind === "spring-boot" ? `:${port}${path?.replace(/\/+$/, "") ?? ""}/` : `:${port}`; +} + +/** A node's grey text: the HTTP address of a running web application, else the state. */ export function sessionDetail(s: RunSession | undefined): string | undefined { - return s && busy(s) && s.httpPort ? `:${s.httpPort}` : sessionStatus(s); + return s && busy(s) && s.httpPort ? portDetail(s.config, s.httpPort, s.httpPath) : sessionStatus(s); } function executionDetail(s: ServiceSession | undefined): string | undefined { @@ -327,8 +337,8 @@ function executionDetail(s: ServiceSession | undefined): string | undefined { // The app's HTTP port: a Run owns the console for an attached debugger, a direct // debug launch announces it on the debug session's own console (#1718). const run = s.run && busy(s.run) ? s.run : undefined; - const port = run?.httpPort ?? debug.httpPort; - if (port) return `:${port}`; + const web = run?.httpPort ? run : debug; + if (web.httpPort) return portDetail(s.config, web.httpPort, web.httpPath); return debug.status === "starting" ? "Starting" : "Debugging"; } return s.run ? sessionDetail(s.run) : "Finished"; @@ -423,19 +433,19 @@ function useRoots(): ServiceTreeItem[] { if (typesRoot !== root) useAddedTypes.setState({ root, types: root ? readTypes(root) : [] }); if (hiddenLocation !== location) useHiddenConfigs.setState({ location, hidden: readHidden(location) }); }, [root, typesRoot, hiddenLocation, location]); - return useMemo( - () => - runServiceItems( - configs, - sessions, - typesRoot === root ? types : [], - order, - debug, - configRemoved, - hiddenLocation === location ? hidden : {}, - ), - [configs, sessions, types, typesRoot, root, order, debug, hidden, hiddenLocation, location], - ); + return useMemo(() => { + const implicit = root !== null && storedTypes(root) === null; + const groups = runServiceItems( + configs, + sessions, + typesRoot === root ? types : [], + order, + debug, + configRemoved, + hiddenLocation === location ? hidden : {}, + ); + return implicit ? groups.filter((group) => group.children?.length) : groups; + }, [configs, sessions, types, typesRoot, root, order, debug, hidden, hiddenLocation, location]); } interface Resolved { diff --git a/src/features/services/ServicesTree.debug.test.tsx b/src/features/services/ServicesTree.debug.test.tsx index c31c2a278b..7a2af1132d 100644 --- a/src/features/services/ServicesTree.debug.test.tsx +++ b/src/features/services/ServicesTree.debug.test.tsx @@ -118,7 +118,7 @@ it("shows the service port announced by a debug session's application", () => { appendConsole(1, "stdout", "Tomcat started on port 8080 (http) with context path '/'\n"); useDebugRunSessions.setState({ serviceSessions: [summary(1, { httpPort: 8080 })] }); render(); - expect(within(screen.getByRole("tree")).getByText(":8080")).toBeTruthy(); + expect(within(screen.getByRole("tree")).getByText(":8080/")).toBeTruthy(); }); it("debugs a service in place without switching to the Debug tool window", async () => {