Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 98764c1da8 fix(debugger): debug Kotlin with kotlin-lsp without asking for kotlin-debug-adapter
Since #3172, debugging a Maven / Gradle run of a module with Kotlin sources stopped before the
build and asked to install kotlin-debug-adapter whenever it was missing, although the backend
debugs Kotlin with kotlin-lsp's own debugger when kotlin-lsp is installed and only falls back
to kotlin-debug-adapter when it can't. The check now offers kotlin-debug-adapter only when
neither is installed.
2026-11-14 10:37:34 +08:00
2 змінених файлів з 36 додано та 3 видалено

No files matched your search

+31 -1
Переглянути файл
@@ -5,6 +5,7 @@ const invoked: Array<[string, unknown[]]> = [];
let shortenCommandLine: string | null = null;
let kotlinFiles = false;
const files: Record<string, string> = {};
let missingTools: string[] = [];
vi.mock("@/platform/ipc", async (orig) => {
const real = await orig<typeof import("@/platform/ipc")>();
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 = [];
}
});
});
+5 -2
Переглянути файл
@@ -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<boolean> {
/**
* 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<boolean> {
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",