mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(debugger): offer the Kotlin debugger before starting a Maven or Gradle debug run (#3172)
Debugging a test in a module with Kotlin sources started Maven / Gradle with a JDWP agent and only found the missing kotlin-debug-adapter when attaching: the Run window flashed, the empty Debug window replaced it and the build was stopped. debugWithAgent now asks the debugger (debug.jvmAttachReady) first; when the adapter is missing the build doesn't start and Install and Debug installs it and debugs again.
This commit is contained in:
@@ -28,7 +28,13 @@ import {
|
||||
import { removeAllSpecial, specialAt, toggleFieldAt, toggleMethodAt } from "./breakpoints/special";
|
||||
import { fieldAt, methodAt } from "./breakpoints/symbols";
|
||||
import { toggleBreakpointSmart } from "./breakpoints/toggle";
|
||||
import { isJavaAttachTarget, isJavaDebuggable, javaAttachConfig, javaLaunchConfig } from "./java";
|
||||
import {
|
||||
isJavaAttachTarget,
|
||||
isJavaDebuggable,
|
||||
javaAttachConfig,
|
||||
javaLaunchConfig,
|
||||
jvmAttachDebuggerReady,
|
||||
} from "./java";
|
||||
import { cancelHotSwapBuild, reloadChangedClasses } from "./hotswap";
|
||||
import { refreshMemory, useMemory } from "./memory/memoryState";
|
||||
import { closeInstances, instancesOutdated, showInstances, showReferrers, useInstances } from "./memory/instancesState";
|
||||
@@ -478,6 +484,20 @@ export function registerDebugActions(): () => void {
|
||||
})(),
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "debug.jvmAttachReady",
|
||||
title: "Check the JVM Debugger",
|
||||
category: "Debug",
|
||||
hidden: true,
|
||||
description:
|
||||
"Whether the debugger for a build tool's JVMs is installed, offering the install when not (arg: { module, retry, done(ready) })",
|
||||
run: ({ arg }) => {
|
||||
const a = arg as { module: string; retry: () => void; done: (ready: boolean) => void };
|
||||
const root = useProject.getState().project?.root;
|
||||
if (!root) return a.done(true);
|
||||
void jvmAttachDebuggerReady(a.module, root, a.retry).then(a.done, () => a.done(true));
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "debug.stop",
|
||||
title: "Stop",
|
||||
|
||||
@@ -80,6 +80,29 @@ export async function moduleHasKotlinSources(cwd: string): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
*/
|
||||
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;
|
||||
notifications().notify({
|
||||
group: "run",
|
||||
level: "warning",
|
||||
key: "debug.start",
|
||||
title: "The Kotlin debugger is not installed",
|
||||
body: "This module has Kotlin sources, so debugging it needs the Kotlin debugger (kotlin-debug-adapter).",
|
||||
sticky: true,
|
||||
actions: [
|
||||
{ label: "Install and Debug", run: () => void executeAction("tools.install", KOTLIN_ADAPTER).then(retry) },
|
||||
],
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
/** java-debug missing from jdtls: offer the one-click install (jdtls restarts with the bundle). */
|
||||
function offerInstall(e: unknown): never {
|
||||
if (e instanceof IpcError && e.kind === "unavailable" && /java-debug|debugger/i.test(e.message)) {
|
||||
|
||||
Reference in New Issue
Block a user