diff --git a/src/features/run/services.test.ts b/src/features/run/services.test.ts index 5c8369b5d7..e985915d6e 100644 --- a/src/features/run/services.test.ts +++ b/src/features/run/services.test.ts @@ -277,6 +277,22 @@ describe("run configurations in Services", () => { expect(runServiceItems([build], [], ["spring-boot"])[0]!.children).toEqual([]); }); + it("shows same-named applications of several modules apart", () => { + const app = (id: string, module: string): RunConfig => ({ + ...config(id, "spring-boot"), + name: "Application", + module, + }); + const items = runServiceItems( + [app("application:svc-a:com.acme.Application", "svc-a"), app("application:svc-b:com.acme.Application", "svc-b")], + [], + ["spring-boot"], + ); + expect(items[0]!.children!.map((c) => c.label)).toEqual(["Application (svc-a)", "Application (svc-b)"]); + const one = runServiceItems([app("application:api:com.acme.Application", "api")], [], ["spring-boot"]); + expect(one[0]!.children!.map((c) => c.label)).toEqual(["Application"]); + }); + 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 }); diff --git a/src/features/run/services.tsx b/src/features/run/services.tsx index 189acfb627..0738e7a5de 100644 --- a/src/features/run/services.tsx +++ b/src/features/run/services.tsx @@ -345,6 +345,22 @@ function executionDetail(s: ServiceSession | undefined): string | undefined { return s.run ? sessionDetail(s.run) : "Finished"; } +/** + * Labels of one type's configurations: a name used in several modules carries its module directory. + */ +function configLabels(entries: readonly RunConfig[]): Map { + const count = new Map(); + for (const c of entries) count.set(c.name, (count.get(c.name) ?? 0) + 1); + const labels = new Map(); + for (const c of entries) { + const relativeCwd = + c.cwd && !c.cwd.startsWith("/") && !c.cwd.startsWith("\\") && !/^[A-Za-z]:/.test(c.cwd) ? c.cwd : null; + const module = c.module ?? relativeCwd; + labels.set(c.id, (count.get(c.name) ?? 0) > 1 && module ? `${c.name} (${module})` : c.name); + } + return labels; +} + /** * Groups by configuration type, then by the configurations' folders (first, as in * Run/Debug Configurations): only the types added in this window list their @@ -372,11 +388,12 @@ export function runServiceItems( const hiddenIds = new Set(hidden[kind] ?? []); const visible = entries.filter((c) => !hiddenIds.has(c.id)); const ordered = orderServices(visible, order[kind]); + const labels = configLabels(visible); const item = (c: RunConfig): ServiceTreeItem => { const s = latest.get(c.id); return { key: CONFIG_PREFIX + c.id, - label: c.name, + label: labels.get(c.id) ?? c.name, icon: serviceDebugger(s) ? "debug" : s && liveServiceSession(s) ? "run" : configIcon(c), detail: executionDetail(s), dim: !s || !liveServiceSession(s),