diff --git a/src/features/debugger/__tests__/java.test.ts b/src/features/debugger/__tests__/java.test.ts index d01dfdc8b..157622b9a 100644 --- a/src/features/debugger/__tests__/java.test.ts +++ b/src/features/debugger/__tests__/java.test.ts @@ -5,6 +5,7 @@ const invoked: Array<[string, unknown[]]> = []; let shortenCommandLine: string | null = null; let kotlinFiles = false; const files: Record = {}; +let missingTools: string[] = []; vi.mock("@/platform/ipc", async (orig) => { const real = await orig(); const ok = (data: unknown) => Promise.resolve({ status: "ok", data }); @@ -20,6 +21,13 @@ vi.mock("@/platform/ipc", async (orig) => { ), fsReadText: (path: string) => ok(files[path] ?? "package a;\npublic class Main {}"), runConfigs: () => ok([]), + toolsList: () => + ok( + ["kotlin-debug-adapter", "kotlin-lsp"].map((name) => ({ + name, + status: missingTools.includes(name) ? "missing" : "installed", + })), + ), fsReadDir: (path: string) => ok( kotlinFiles && path.endsWith("/src") @@ -50,7 +58,8 @@ vi.mock("@/platform/ipc", async (orig) => { }; }); -const { isJavaDebuggable, javaAttachConfig, javaLaunchConfig, javaProjectName } = await import("../java"); +const { isJavaDebuggable, javaAttachConfig, javaLaunchConfig, javaProjectName, jvmAttachDebuggerReady } = + await import("../java"); const app: RunConfig = { id: "application:a.Main", @@ -233,3 +242,24 @@ it("reports a save failure before starting Java Debug", async () => { ).rejects.toThrow("save failed"); expect(invoked).toEqual([]); }); + +describe("the debugger for a build tool's JVMs", () => { + it("is ready for Kotlin sources when kotlin-lsp or kotlin-debug-adapter is installed", async () => { + kotlinFiles = true; + const retry = vi.fn(); + try { + for (const missing of [[], ["kotlin-debug-adapter"], ["kotlin-lsp"]]) { + missingTools = missing; + expect(await jvmAttachDebuggerReady("app", "/p", retry)).toBe(true); + } + missingTools = ["kotlin-debug-adapter", "kotlin-lsp"]; + expect(await jvmAttachDebuggerReady("app", "/p", retry)).toBe(false); + kotlinFiles = false; + expect(await jvmAttachDebuggerReady("app", "/p", retry)).toBe(true); + expect(retry).not.toHaveBeenCalled(); + } finally { + kotlinFiles = false; + missingTools = []; + } + }); +}); diff --git a/src/features/debugger/java.ts b/src/features/debugger/java.ts index 06bdef012..55ef41c96 100644 --- a/src/features/debugger/java.ts +++ b/src/features/debugger/java.ts @@ -20,6 +20,7 @@ import { withEnvFiles } from "./launch"; export const JAVA_ADAPTER = "java-debug"; export const KOTLIN_ADAPTER = "kotlin-debug-adapter"; +const KOTLIN_LSP = "kotlin-lsp"; export function isJavaDebuggable(rc: RunConfig): boolean { return isJvmApplication(rc) && [JAVA_ADAPTER, KOTLIN_ADAPTER].includes(rc.debugAdapter ?? JAVA_ADAPTER); @@ -83,12 +84,14 @@ export async function moduleHasKotlinSources(cwd: string): Promise { /** * Whether the debugger for the JVMs of `module` is installed. Maven / Gradle start those JVMs * before the debugger attaches, so a missing Kotlin debugger is offered here, before the build - * runs: "Install and Debug" installs it and calls `retry`. + * runs: "Install and Debug" installs it and calls `retry`. An installed kotlin-lsp debugs Kotlin + * itself (the backend falls back to kotlin-debug-adapter only when it can't). */ export async function jvmAttachDebuggerReady(module: string, root: string, retry: () => void): Promise { if (!(await moduleHasKotlinSources(module ? join(root, module) : root))) return true; const tools = await call(commands.toolsList()).catch(() => []); - if (tools.find((t) => t.name === KOTLIN_ADAPTER)?.status !== "missing") return true; + const missing = (name: string) => tools.find((t) => t.name === name)?.status === "missing"; + if (!missing(KOTLIN_ADAPTER) || !missing(KOTLIN_LSP)) return true; notifications().notify({ group: "run", level: "warning",