Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

feat(debugger): Reload Changed Classes in the editor context menu (#1627)

l0ng-aib4bd0ec1e2fd
diff --git a/src/features/debugger/__tests__/hotswap.test.ts b/src/features/debugger/__tests__/hotswap.test.ts
index 3473a32b1..6ce4e5a6f 100644
--- a/src/features/debugger/__tests__/hotswap.test.ts
+++ b/src/features/debugger/__tests__/hotswap.test.ts
@@ -30,7 +30,7 @@ vi.mock("@/workbench/contributions", async (importOriginal) => {
import type { DebugCapabilities, DebugSessionId } from "@/platform/ipc";
import { getContext } from "@/platform/context";
import { _resetI18nForTests, setLocale } from "@/platform/i18n";
-import { hotSwapMessage, onHotCodeReplace, reloadChangedClasses } from "../hotswap";
+import { hotSwapMenuItems, hotSwapMessage, onHotCodeReplace, reloadChangedClasses } from "../hotswap";
import { publishContext, useDebug, type DebugSession } from "../state";
function session(id: number, hotCodeReplace: boolean): DebugSession {
@@ -80,6 +80,13 @@ describe("HotSwap", () => {
expect(getContext().debugCanHotSwap).toBe(false);
});
+ it("offers the reload in the editor menu of a Java file while a session can reload classes", () => {
+ expect(hotSwapMenuItems(["/p/app/src/A.java"])).toEqual([{ kind: "action", action: "debug.reloadChangedClasses" }]);
+ expect(hotSwapMenuItems(["/p/app/pom.xml"])).toEqual([]);
+ useDebug.setState({ sessions: { 2: session(2, false) }, active: 2 });
+ expect(hotSwapMenuItems(["/p/app/src/A.java"])).toEqual([]);
+ });
+
it("builds, reloads in Java sessions and reports the count", async () => {
await reloadChangedClasses();
expect(ipc.javaBuildWorkspace).toHaveBeenCalledWith("/p/app");
diff --git a/src/features/debugger/hotswap.ts b/src/features/debugger/hotswap.ts
index b24eb225b..e4e039232 100644
--- a/src/features/debugger/hotswap.ts
+++ b/src/features/debugger/hotswap.ts
@@ -9,6 +9,7 @@ import { call, commands, isTauri, type DebugEvent, type DebugSessionId } from "@
import { maybeEditorService, notifications } from "@/workbench/contributions";
import { isLive, useDebug, type DebugSession } from "./state";
import { tx } from "@/platform/i18n";
+import type { MenuItem } from "@/ui/Menu";
const KEY = "debug.hotswap";
/** `BUILD_COMPLETE` events of our own build are not worth a prompt. */
@@ -18,6 +19,12 @@ export function hotSwapSessions(): DebugSession[] {
return Object.values(useDebug.getState().sessions).filter((s) => isLive(s) && !!s.caps?.hotCodeReplace);
}
+/** Editor menu: Reload Changed Classes on a Java file while a debug session can reload classes. */
+export function hotSwapMenuItems(paths: readonly string[]): MenuItem[] {
+ const java = paths.length === 1 && /\.java$/i.test(paths[0]!);
+ return java && hotSwapSessions().length ? [{ kind: "action", action: "debug.reloadChangedClasses" }] : [];
+}
+
/** "3 classes", translated per count (the sentence around it is translated on its own). */
const classesText = (n: number) => (n === 1 ? tx`${n} class` : tx`${n} classes`);
diff --git a/src/features/debugger/index.ts b/src/features/debugger/index.ts
index 5c606dfa6..0414745d4 100644
--- a/src/features/debugger/index.ts
+++ b/src/features/debugger/index.ts
@@ -24,7 +24,7 @@ import { breakpointGutter } from "./editor/breakpointGutter";
import { executionPoint } from "./editor/execution";
import { runToCursorInlay } from "./editor/runToCursor";
import { installSmartStepPicking, smartStepTargets } from "./editor/smartStep";
-import { onHotCodeReplace } from "./hotswap";
+import { hotSwapMenuItems, onHotCodeReplace } from "./hotswap";
import {
activeSession,
handleDebugEvent,
@@ -68,6 +68,11 @@ export function activate(): () => void {
menus: ["editor"],
items: () => (activeSession()?.status === "paused" ? [{ kind: "action", action: "debug.evaluate" }] : []),
}),
+ registerMenuGroup({
+ id: "debugger.hotswap",
+ menus: ["editor"],
+ items: (_menu, { paths }) => hotSwapMenuItems(paths),
+ }),
// Stop (⌘F2) offers the running debug sessions beside run processes.
registerMenuGroup({
id: "debugger.stop",