дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Native debug sessions whose adapter supports disassemble get a Disassembly tab showing the selected frame's instructions with the program counter highlighted, following stepping and frame selection, including frames without source. Show Disassembly is on the Frames list; Step Over Instruction and Step Into Instruction send steps with instruction granularity and are disabled with a reason when the adapter lacks it. Frames keep instructionPointerReference; when the PC is not where the requested window expects it, the view reads again from the PC. lldb-dap sends instruction bytes already spaced and pads mnemonics unevenly; the view strips the spacing before grouping the bytes and pads mnemonics to one width. Part of #5922 Co-authored-by: bertyhell <[email protected]>
1366 рядки
49 KiB
TypeScript
1366 рядки
49 KiB
TypeScript
/** Debugger actions (ids match `keymaps/intellij-macos.ts`). */
|
||
import { executeAction, getAction, registerActions, type Action } from "@/platform/actions";
|
||
import {
|
||
call,
|
||
commands,
|
||
isCancelled,
|
||
isTauri,
|
||
nextRequestId,
|
||
type AttachableProcess,
|
||
type DebugSessionId,
|
||
type LaunchConfig,
|
||
type RunConfig,
|
||
type RunId,
|
||
} from "@/platform/ipc";
|
||
import { downloadJdkActions } from "@/platform/jdk";
|
||
import { followLaunchBuild } from "@/features/build/store";
|
||
import { useProject } from "@/platform/project";
|
||
import { isRemoteWindow } from "@/platform/remote";
|
||
import { openExternalUrl } from "@/platform/openUrl";
|
||
import { activeEditor } from "@/editor/api";
|
||
import type { EditorView } from "@codemirror/view";
|
||
import { maybeEditorService, notifications, showStatusInfo, toolWindowService } from "@/workbench/contributions";
|
||
import { classFileBreakpointReason } from "@/platform/classFiles";
|
||
import { lineHasCode } from "./breakpoints/codeLines";
|
||
import { canPlaceBreakpoint, templateBreakpoints } from "./breakpoints/languages";
|
||
import {
|
||
breakpointsOf,
|
||
removeAllBreakpoints,
|
||
removeFileBreakpoints,
|
||
setMuted,
|
||
toggleBreakpoint,
|
||
toggleTemporaryBreakpoint,
|
||
updateBreakpoint,
|
||
useBreakpoints,
|
||
} from "./breakpoints/store";
|
||
import {
|
||
removeAllSpecial,
|
||
removeSpecialIn,
|
||
specialAt,
|
||
toggleFieldAt,
|
||
toggleMethodAt,
|
||
updateSpecial,
|
||
} from "./breakpoints/special";
|
||
import { removeAllExceptionClasses } from "./breakpoints/exceptionClasses";
|
||
import { fieldAt, methodAt } from "./breakpoints/symbols";
|
||
import { toggleBreakpointSmart } from "./breakpoints/toggle";
|
||
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";
|
||
import { jumpToClass } from "./memory/jumpToClass";
|
||
import { revealMemoryView, showMemoryAt } from "./memoryView/memoryViewState";
|
||
import { revealDisassembly } from "./disassembly/disassemblyState";
|
||
import { captureHeap } from "./heap/heapState";
|
||
import { stopRecording, traceStreamChain } from "./streams/streamState";
|
||
import { isTracing, useStreamTrace } from "./streams/streamStore";
|
||
import { startPageProfile, stopPageProfile } from "./js/profile";
|
||
import { activeCapturedSnapshot, openHeapDump, saveHeapDump } from "./heap/heapDumpFiles";
|
||
import { browserLaunch, browserLaunchConfig, browserUrl, installedDebugBrowser, isBrowserConfig } from "./browser";
|
||
import { warnPinnedFlutterDevice } from "@/workbench/flutterDevices";
|
||
import { DEVTOOLS_WINDOWS, devToolsUrl, refreshDevTools, WIDGET_PREVIEW_WINDOW } from "./flutter/devTools";
|
||
import { debugUnsupportedReason, launchConfigFor, withEnvFiles } from "./launch";
|
||
import { attachConfig } from "./attach";
|
||
import {
|
||
isPythonAttachTarget,
|
||
isRemoteConfig,
|
||
pythonAttachConfig,
|
||
REMOTE_JVM,
|
||
remoteAttachConfig,
|
||
remoteJvmTarget,
|
||
} from "./remote";
|
||
import {
|
||
activeSession,
|
||
resumeExecution,
|
||
evaluate,
|
||
isLive,
|
||
justDetached,
|
||
markInstructionStep,
|
||
pausedThread,
|
||
rerunSession,
|
||
revealFrame,
|
||
rootOf,
|
||
selectedFrame,
|
||
selectFrame,
|
||
sessionSupports,
|
||
showExecutionPoint,
|
||
startBrowserSession,
|
||
startSession,
|
||
startPreparedSession,
|
||
stopSession,
|
||
stopAssociatedProcess,
|
||
stopTarget,
|
||
useDebug,
|
||
type DebugSession,
|
||
} from "./state";
|
||
import { focusedDebugView } from "./ui/focusedView";
|
||
import { browseFocusedConsoleHistory } from "./ui/expressionHistory";
|
||
import { expressionAt, showQuickValue } from "./editor/valueTooltip";
|
||
import { mouseEvaluateTarget } from "./editor/quickEvaluate";
|
||
import { showHint } from "@/editor/lsp/hint";
|
||
import { pausedLineTargets, startInlineSmartStep } from "./editor/smartStep";
|
||
import {
|
||
openBreakpointsDialog,
|
||
openConfigChooser,
|
||
openEvaluateDialog,
|
||
openSmartStepChooser,
|
||
useOverlays,
|
||
} from "./ui/popoverStore";
|
||
import { tx } from "@/platform/i18n";
|
||
import { openAttachPopup } from "./attachPopup";
|
||
|
||
function isRunConfig(arg: unknown): arg is RunConfig {
|
||
return !!arg && typeof arg === "object" && "command" in arg && "args" in arg && "debugAdapter" in arg;
|
||
}
|
||
|
||
/** `debug.attach`'s argument for a process listed by Attach to Process (a plugin run's child). */
|
||
function isAttachableTarget(
|
||
arg: unknown,
|
||
): arg is { attachable: AttachableProcess; process?: RunId | null; runConfig?: RunConfig; show?: boolean } {
|
||
const a = (arg && typeof arg === "object" ? arg : {}) as { attachable?: Partial<AttachableProcess> };
|
||
return typeof a.attachable?.pid === "number" && typeof a.attachable.kind === "string";
|
||
}
|
||
|
||
/**
|
||
* Names the run the attach debugs (`RUN_LINK` in ide-dap, kept from the adapter): the run's Dump
|
||
* Threads then goes through the session, which knows whether the JVM is stopped.
|
||
*/
|
||
function linkedToRun(launch: LaunchConfig, run: RunId): LaunchConfig {
|
||
const extra = launch.extraJson ? (JSON.parse(launch.extraJson) as Record<string, unknown>) : {};
|
||
return { ...launch, extraJson: JSON.stringify({ ...extra, __openideaRun: run }) };
|
||
}
|
||
|
||
function errorText(e: unknown) {
|
||
return e instanceof Error ? e.message : String(e);
|
||
}
|
||
|
||
async function report(title: string, p: Promise<unknown>) {
|
||
try {
|
||
await p;
|
||
} catch (e) {
|
||
// A Java launch without a JDK new enough (for jdtls or the project) offers to download one.
|
||
const actions = downloadJdkActions(errorText(e));
|
||
notifications().notify({ group: "run", level: "error", title, body: errorText(e), key: "debug.action", actions });
|
||
}
|
||
}
|
||
|
||
/** The paused session and the thread to act on. */
|
||
function pausedTarget(): { s: DebugSession; thread: number } | null {
|
||
const s = activeSession();
|
||
if (!s || s.status !== "paused") return null;
|
||
const thread = pausedThread(s);
|
||
return thread == null ? null : { s, thread };
|
||
}
|
||
|
||
/** The trace tab passes its own session; from elsewhere, the active session's trace. */
|
||
function traceTarget(arg: unknown): DebugSessionId | undefined {
|
||
return typeof arg === "number" ? arg : activeSession()?.id;
|
||
}
|
||
|
||
function breakpointPathAllowed(path: string): boolean {
|
||
const reason = classFileBreakpointReason(path);
|
||
if (!reason) return true;
|
||
showStatusInfo(tx(reason));
|
||
return false;
|
||
}
|
||
|
||
/** Run to Cursor at `line` (0-based) of `path` in the paused session. */
|
||
export function runToLine(path: string, line: number) {
|
||
const t = pausedTarget();
|
||
if (t && breakpointPathAllowed(path))
|
||
void report(
|
||
tx("Run to Cursor failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugRunTo(t.s.id, t.thread, path, line, false))),
|
||
);
|
||
}
|
||
|
||
function notSupported(what: string, s: DebugSession) {
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "info",
|
||
key: "debug.unsupported",
|
||
title: `${what} is not supported by ${s.adapter || "this debugger"}`,
|
||
});
|
||
}
|
||
|
||
/**
|
||
* View Memory: the Memory View, at `reference` (a variable's or watch's memory reference) when given.
|
||
* Adapters without `readMemory` (most besides the native ones) say so instead.
|
||
*/
|
||
function viewMemory(reference: unknown) {
|
||
const s = activeSession();
|
||
if (!s || !isLive(s)) return;
|
||
if (!sessionSupports("readMemory", s)) return notSupported("View Memory", s);
|
||
// The address field shows the address itself: entered again, it reads the same memory.
|
||
if (typeof reference === "string") void showMemoryAt(s.id, reference, reference);
|
||
revealMemoryView();
|
||
toolWindowService().show("debug", true);
|
||
}
|
||
|
||
/**
|
||
* Show Disassembly: the Disassembly view, at the frame `frameId` (from the Frames list) when given,
|
||
* otherwise at the selected frame. Adapters without `disassemble` say so instead.
|
||
*/
|
||
function showDisassembly(frameId: unknown) {
|
||
const s = activeSession();
|
||
if (!s || !isLive(s)) return;
|
||
if (!sessionSupports("disassemble", s)) return notSupported("Disassembly", s);
|
||
if (typeof frameId === "number" && s.status === "paused" && s.frames.some((f) => f.id === frameId))
|
||
selectFrame(s.id, frameId, false);
|
||
revealDisassembly();
|
||
toolWindowService().show("debug", true);
|
||
}
|
||
|
||
/**
|
||
* Smart Step Into: the calls on the current line, picked in the editor (the
|
||
* dialog when they cannot be placed); one call (or none) steps straight in, like IDEA.
|
||
*/
|
||
async function smartStepInto() {
|
||
const t = pausedTarget();
|
||
if (!t) return;
|
||
const frame = selectedFrame(t.s);
|
||
if (!frame || !sessionSupports("stepInTargets", t.s)) {
|
||
await resumeExecution(t.s.id, () => call(commands.debugStep(t.s.id, t.thread, "into")));
|
||
return;
|
||
}
|
||
const targets = pausedLineTargets(await call(commands.debugStepInTargets(t.s.id, frame.id)));
|
||
if (targets.length <= 1) {
|
||
await resumeExecution(t.s.id, () =>
|
||
call(
|
||
targets[0]
|
||
? commands.debugStepInTarget(t.s.id, t.thread, targets[0].id)
|
||
: commands.debugStep(t.s.id, t.thread, "into"),
|
||
),
|
||
);
|
||
return;
|
||
}
|
||
if (!startInlineSmartStep(t.s.id, t.thread, targets)) openSmartStepChooser(t.s.id, t.thread, targets);
|
||
}
|
||
|
||
function cursor(): { path: string; line: number; selection: string } | null {
|
||
const ed = activeEditor();
|
||
if (!ed) return null;
|
||
const { state } = ed.view;
|
||
const main = state.selection.main;
|
||
return {
|
||
path: ed.ctx.path,
|
||
line: state.doc.lineAt(main.head).number - 1,
|
||
selection: state.sliceDoc(main.from, main.to),
|
||
};
|
||
}
|
||
|
||
/** Toggle Breakpoint Enabled's subject, as in IDEA: the breakpoints on the lines each caret or selection spans. */
|
||
function breakpointsOnCaretLines() {
|
||
const ed = activeEditor();
|
||
if (!ed) return null;
|
||
const { state } = ed.view;
|
||
const path = ed.ctx.path;
|
||
const spans = state.selection.ranges.map((r) => ({
|
||
from: state.doc.lineAt(r.from).number - 1,
|
||
to: state.doc.lineAt(r.to).number - 1,
|
||
}));
|
||
const on = (line: number) => spans.some((s) => line >= s.from && line <= s.to);
|
||
return {
|
||
path,
|
||
lines: breakpointsOf(path).filter((b) => on(b.line)),
|
||
special: specialAt(path).filter((b) => on(b.line!)),
|
||
};
|
||
}
|
||
|
||
/** Evaluate's initial text, as in IDEA: the selection, else the expression at the caret. */
|
||
function evaluateSeed(view: EditorView | undefined = activeEditor()?.view, pos?: number): string {
|
||
if (!view) return "";
|
||
const { state } = view;
|
||
const sel = state.selection.main;
|
||
if (!sel.empty && (pos == null || (sel.from <= pos && pos <= sel.to))) return state.sliceDoc(sel.from, sel.to);
|
||
return expressionAt(view, pos ?? sel.head, { calls: true })?.text ?? "";
|
||
}
|
||
|
||
async function quickEvaluate(arg?: unknown) {
|
||
const target = mouseEvaluateTarget(arg);
|
||
const view = target?.view ?? activeEditor()?.view;
|
||
if (!view) return;
|
||
const { doc, selection } = view.state;
|
||
const pos = target?.pos ?? selection.main.from;
|
||
const expression = evaluateSeed(view, target?.pos).trim();
|
||
if (!expression) return showHint(view, "Nothing to evaluate at the caret");
|
||
const session = activeSession();
|
||
const stop = useDebug.getState().stopSeq;
|
||
const stillCurrent = () => {
|
||
const current = activeSession();
|
||
return (
|
||
view.dom.isConnected &&
|
||
view.state.doc === doc &&
|
||
view.state.selection.eq(selection) &&
|
||
current?.status === "paused" &&
|
||
current.id === session?.id &&
|
||
current.selectedFrame === session?.selectedFrame &&
|
||
useDebug.getState().stopSeq === stop
|
||
);
|
||
};
|
||
try {
|
||
// Unlike a plain hover, an explicit Quick Evaluate may call methods (adapters refuse that for "hover").
|
||
const value = await evaluate(expression, "watch", session);
|
||
if (session && stillCurrent()) showQuickValue(view, pos, expression, value, session.id);
|
||
} catch (e) {
|
||
if (stillCurrent()) showHint(view, e instanceof Error ? e.message : String(e), { pos, tone: "error" });
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Remote JVM Debug in listen mode: the IDE listens and the remote JVM connects; java-debug
|
||
* then attaches through a loopback relay. Null when cancelled.
|
||
*/
|
||
async function listenForJvm(name: string, host: string, port: number): Promise<number | null> {
|
||
const request = nextRequestId();
|
||
const key = `debug.listen.${request}`;
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "info",
|
||
key,
|
||
sticky: true,
|
||
title: `'${name}': listening for the remote JVM on port ${port}`,
|
||
body: tx`Start the remote JVM with -agentlib:jdwp=transport=dt_socket,server=n,address=${host}:${port},suspend=y`,
|
||
actions: [{ label: "Cancel", run: () => void commands.cancelRequest(request) }],
|
||
});
|
||
try {
|
||
return await call(commands.debugListenForJvm(request, host, port));
|
||
} catch (e) {
|
||
if (isCancelled(e)) return null;
|
||
throw e;
|
||
} finally {
|
||
notifications().expire?.(key);
|
||
}
|
||
}
|
||
|
||
/** Remote JVM Debug, Go Remote, Python / Node.js remote: attach over host:port. */
|
||
async function startRemote(config: RunConfig, root: string, show?: boolean) {
|
||
if (config.kind === REMOTE_JVM) {
|
||
const t = remoteJvmTarget(config);
|
||
let hostName = t.host;
|
||
let port = t.port;
|
||
if (t.mode === "listen") {
|
||
const relay = await listenForJvm(config.name, t.host, t.port);
|
||
if (relay == null) return;
|
||
[hostName, port] = ["127.0.0.1", relay];
|
||
}
|
||
const launch = await javaAttachConfig({ name: config.name, module: t.module, hostName, port }, root);
|
||
// A listen relay accepts one debugger: rerunning listens again through the configuration.
|
||
await startSession(launch, { runConfig: config, rerunnable: t.mode === "attach", show });
|
||
return;
|
||
}
|
||
const launch = remoteAttachConfig(config, root);
|
||
if (launch) await startSession(launch, { runConfig: config, show });
|
||
}
|
||
|
||
/** The browser opens on this desktop, which a remote project's debugger can't reach. */
|
||
function browserUnavailable(name: string): boolean {
|
||
if (!isRemoteWindow()) return false;
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "warning",
|
||
title: `“${name}” can't be debugged`,
|
||
body: "JavaScript Debug isn't available in a remote project yet.",
|
||
});
|
||
return true;
|
||
}
|
||
|
||
/** The browser opens on this desktop, which can't reach a server on a remote project's machine. */
|
||
async function openDevTools(vmServiceUri: string) {
|
||
if (isRemoteWindow()) {
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "warning",
|
||
title: "Flutter DevTools isn't available in a remote project yet",
|
||
});
|
||
return;
|
||
}
|
||
const server = await call(commands.flutterDevtoolsUrl());
|
||
await openExternalUrl(devToolsUrl(server, { page: "inspector" }, { uri: vmServiceUri }));
|
||
}
|
||
|
||
async function startBrowser(config: RunConfig, root: string, show?: boolean) {
|
||
if (browserUnavailable(config.name)) return;
|
||
const launch = browserLaunchConfig(config, root);
|
||
if (launch) await startBrowserSession(launch, { runConfig: config, show });
|
||
}
|
||
|
||
/** Debugs the page at a URL without a configuration (a link in a console). */
|
||
async function debugInBrowser(arg: unknown) {
|
||
const root = useProject.getState().project?.root;
|
||
const url = typeof arg === "string" ? browserUrl(arg) : null;
|
||
if (!root || !url) return;
|
||
const name = new URL(url).host || url;
|
||
if (browserUnavailable(name)) return;
|
||
await startBrowserSession(browserLaunch(name, url, await installedDebugBrowser(), root));
|
||
}
|
||
|
||
/** Preparation belongs to a session from the moment the action begins. */
|
||
async function startJavaConfig(config: RunConfig, root: string, origin: RunConfig, show?: boolean) {
|
||
await startPreparedSession(
|
||
origin,
|
||
async (signal, report) => {
|
||
const request = nextRequestId();
|
||
const cancel = () => {
|
||
void commands.cancelRequest(request).catch(() => undefined);
|
||
};
|
||
signal.addEventListener("abort", cancel, { once: true });
|
||
try {
|
||
return await javaLaunchConfig(config, root, {
|
||
request,
|
||
signal,
|
||
report,
|
||
build: followLaunchBuild(request, tx`Build before launch: ${config.name}`, report),
|
||
saveAll: async () => {
|
||
await maybeEditorService()?.saveAll();
|
||
},
|
||
});
|
||
} finally {
|
||
signal.removeEventListener("abort", cancel);
|
||
}
|
||
},
|
||
{ show },
|
||
);
|
||
}
|
||
|
||
async function startConfig(arg: unknown) {
|
||
const root = useProject.getState().project?.root;
|
||
if (!root) return;
|
||
const origin = arg && typeof arg === "object" && "origin" in arg && isRunConfig(arg.origin) ? arg.origin : null;
|
||
const show = arg && typeof arg === "object" && "show" in arg ? (arg as { show?: boolean }).show : undefined;
|
||
const input = arg && typeof arg === "object" && "config" in arg ? arg.config : arg;
|
||
let config: RunConfig | null = isRunConfig(input) ? input : null;
|
||
if (!config) {
|
||
if (!isTauri()) {
|
||
notifications().notify({ group: "run", level: "warning", title: "Debugging needs the desktop app" });
|
||
return;
|
||
}
|
||
const configs = (await call(commands.runConfigs())).filter((c) => c.debugAdapter);
|
||
if (!configs.length) {
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "info",
|
||
title: "Nothing to debug",
|
||
body: "No run configuration in this project has a debug adapter.",
|
||
});
|
||
return;
|
||
}
|
||
if (configs.length > 1) {
|
||
openConfigChooser(configs);
|
||
return;
|
||
}
|
||
config = configs[0]!;
|
||
// Through Run's debug flow: Maven / Gradle / scripts start the JVM with a JDWP agent there.
|
||
if (getAction("run.debugConfig")) {
|
||
await executeAction("run.debugConfig", show === false ? { config, show: false } : config);
|
||
return;
|
||
}
|
||
}
|
||
if (isRemoteConfig(config)) {
|
||
await startRemote(config, root, show);
|
||
return;
|
||
}
|
||
if (isBrowserConfig(config)) {
|
||
await startBrowser(config, root, show);
|
||
return;
|
||
}
|
||
if (isJavaDebuggable(config)) {
|
||
await startJavaConfig(config, root, origin ?? config, show);
|
||
return;
|
||
}
|
||
if (config.kind === "plugin") config = await call(commands.pluginPrepareDebugRun(config));
|
||
const dotnet = config.kind === "dotnet" && config.debugAdapter === "netcoredbg";
|
||
const prepared = dotnet ? await call(commands.runDotnetResolve(config, true)) : config;
|
||
// php-debug starts the PHP chosen in Settings unless the command names one.
|
||
const php =
|
||
config.debugAdapter === "php-debug" && isTauri() ? await call(commands.sdkPhpEffective()).catch(() => null) : null;
|
||
const templates = prepared.debugAdapter === "debugpy" ? await templateBreakpoints() : undefined;
|
||
const launch = launchConfigFor(await withEnvFiles(prepared, root), root, php, templates);
|
||
if (!launch) {
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "warning",
|
||
title: `“${config.name}” can't be debugged`,
|
||
body: debugUnsupportedReason(config) ?? "It has no debug adapter.",
|
||
});
|
||
return;
|
||
}
|
||
if (config.debugAdapter === "dart") warnPinnedFlutterDevice(config);
|
||
const xdebugCheck = config.debugAdapter === "php-debug" && isTauri() ? warnWithoutXdebug(launch) : null;
|
||
await maybeEditorService()
|
||
?.saveAll()
|
||
.catch(() => undefined);
|
||
await startSession(launch, { runConfig: origin ?? config, show });
|
||
await xdebugCheck;
|
||
}
|
||
|
||
/**
|
||
* A PHP without the Xdebug extension ignores the `-dxdebug.*` options php-debug starts it with: the
|
||
* script runs past every breakpoint. Warns, without holding the session back (a command may load
|
||
* Xdebug itself with `-dzend_extension=`).
|
||
*/
|
||
async function warnWithoutXdebug(launch: LaunchConfig) {
|
||
const runtime = (JSON.parse(launch.extraJson ?? "{}") as { runtimeExecutable?: string }).runtimeExecutable;
|
||
// Without one, php-debug runs the `php` on the search path.
|
||
const php = runtime ?? (await call(commands.sdkLocateTools(["php"], null)).catch(() => null))?.tools[0]?.path;
|
||
// In the session's folder: a version manager's `php` shim picks the PHP from it.
|
||
const probe = php ? await call(commands.sdkPhpXdebug(php, launch.cwd)).catch(() => null) : null;
|
||
if (!probe || probe.xdebug) return;
|
||
notifications().notify({
|
||
group: "run",
|
||
level: "warning",
|
||
key: "debug.phpXdebug",
|
||
title: `Xdebug is not loaded in PHP ${probe.phpVersion}`,
|
||
body: tx`${probe.php} runs without Xdebug, so breakpoints are skipped. Install Xdebug 3 for this PHP or choose another PHP interpreter.`,
|
||
actions: [{ label: "Open PHP Settings", run: () => void executeAction("file.settings", "languages.php") }],
|
||
});
|
||
}
|
||
|
||
export function registerDebugActions(): () => void {
|
||
// A stream trace runs the program from the paused thread, so nothing may move it until the trace ends.
|
||
const paused = "debugSessionPaused && !debugStreamTracing";
|
||
const step = (id: string, title: string, kind: "over" | "into" | "out", icon: string): Action => ({
|
||
id,
|
||
title,
|
||
category: "Debug",
|
||
icon,
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (t)
|
||
void report(
|
||
title,
|
||
resumeExecution(t.s.id, () => call(commands.debugStep(t.s.id, t.thread, kind))),
|
||
);
|
||
},
|
||
});
|
||
|
||
// Its stop selects the frame that holds the program counter, also one without source.
|
||
const stepInstruction = (id: string, title: string, kind: "over" | "into", icon: string): Action => ({
|
||
id,
|
||
title,
|
||
category: "Debug",
|
||
icon,
|
||
keywords: ["instruction", "assembly", "disassembly", "machine code"],
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (!t) return;
|
||
if (!sessionSupports("instructionStepping", t.s)) return notSupported(title, t.s);
|
||
markInstructionStep(t.s.id, true);
|
||
const sent = resumeExecution(t.s.id, () => call(commands.debugStepInstruction(t.s.id, t.thread, kind)));
|
||
void report(
|
||
title,
|
||
sent.catch((e: unknown) => {
|
||
markInstructionStep(t.s.id, false);
|
||
throw e;
|
||
}),
|
||
);
|
||
},
|
||
});
|
||
|
||
return registerActions([
|
||
{
|
||
id: "debug.pluginStart",
|
||
title: "Debug Plugin Configuration",
|
||
category: "Debug",
|
||
hidden: true,
|
||
when: "projectOpen",
|
||
run: async ({ arg }) => {
|
||
const a = arg as { config: RunConfig; onExit: (code: number | null, stopped: boolean) => void };
|
||
const config = await call(commands.pluginPrepareDebugRun(a.config));
|
||
const root = useProject.getState().project?.root;
|
||
if (!root) throw new Error("No project");
|
||
const templates = config.debugAdapter === "debugpy" ? await templateBreakpoints() : undefined;
|
||
const launch = launchConfigFor(await withEnvFiles(config, root), root, null, templates);
|
||
if (!launch) throw new Error("This configuration has no debugger");
|
||
let id: number | null = null;
|
||
let stopped = false;
|
||
const observe = () => {
|
||
if (id === null) return;
|
||
const session = useDebug.getState().sessions[id];
|
||
if (session?.status === "stopping") stopped = true;
|
||
if (!session || session.status === "terminated") {
|
||
off();
|
||
a.onExit(session?.exitCode ?? null, stopped);
|
||
}
|
||
};
|
||
const off = useDebug.subscribe(observe);
|
||
try {
|
||
await maybeEditorService()?.saveAll();
|
||
id = await startSession(launch, { runConfig: config });
|
||
if (id === null) {
|
||
off();
|
||
throw new Error("Debug session did not start");
|
||
}
|
||
observe();
|
||
} catch (error) {
|
||
off();
|
||
throw error;
|
||
}
|
||
},
|
||
},
|
||
{
|
||
id: "debug.startConfig",
|
||
title: "Debug…",
|
||
category: "Debug",
|
||
icon: "debug",
|
||
description: "Start debugging a run configuration",
|
||
run: ({ arg }) => report(tx("Cannot start debugging"), startConfig(arg)),
|
||
},
|
||
{
|
||
id: "debug.attach",
|
||
title: "Attach Debugger",
|
||
category: "Debug",
|
||
hidden: true,
|
||
// Also debugpy to a Python program in a run target's container
|
||
// (arg: { name, adapter: "debugpy", hostName, port, remoteRoot, process }).
|
||
// Also a process from Attach to Process (arg: { attachable, process, runConfig }).
|
||
description:
|
||
"Attach the Java debugger to a JVM listening for JDWP (arg: { name, module, hostName, port, process })",
|
||
run: ({ arg }) =>
|
||
report(
|
||
tx("Cannot attach the debugger"),
|
||
(async () => {
|
||
const root = useProject.getState().project?.root;
|
||
if (!root) return;
|
||
let launch: LaunchConfig;
|
||
if (isAttachableTarget(arg)) launch = await attachConfig(arg.attachable, root);
|
||
else if (isPythonAttachTarget(arg)) launch = pythonAttachConfig(arg, root);
|
||
else if (isJavaAttachTarget(arg)) launch = await javaAttachConfig(arg, root);
|
||
else return;
|
||
const process = (arg.process ?? null) as RunId | null;
|
||
if (process != null) launch = linkedToRun(launch, process);
|
||
// Another JVM of the same run (a Gradle test worker, the one just detached) keeps it.
|
||
const shared =
|
||
process != null &&
|
||
(justDetached(process) ||
|
||
Object.values(useDebug.getState().sessions).some((s) => s.process === process && isLive(s)));
|
||
const session = await startSession(launch, {
|
||
process,
|
||
runConfig: arg.runConfig,
|
||
rerunnable: false,
|
||
show: (arg as { show?: boolean }).show,
|
||
});
|
||
// The process was started for this debugger and waits for it (`suspend=y`): without
|
||
// the attach it would never go on, and Stop on the finished session can't reach it.
|
||
if (session == null && process != null && !shared) await stopAssociatedProcess(process);
|
||
})(),
|
||
),
|
||
},
|
||
{
|
||
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",
|
||
category: "Debug",
|
||
icon: "stop",
|
||
when: "debugCanStop",
|
||
run: () => {
|
||
const s = stopTarget();
|
||
if (s) void stopSession(s.id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.reloadChangedClasses",
|
||
title: "Reload Changed Classes",
|
||
description: "HotSwap: compile and reload the changed classes into the running Java debug session",
|
||
category: "Debug",
|
||
icon: "refresh",
|
||
keywords: ["hotswap", "hot swap", "hot code replace"],
|
||
when: "debugCanHotSwap",
|
||
run: ({ arg }) =>
|
||
reloadChangedClasses(
|
||
true,
|
||
typeof arg === "object" && arg !== null && "configId" in arg && typeof arg.configId === "string"
|
||
? arg.configId
|
||
: undefined,
|
||
typeof arg === "object" && arg !== null && "allowBuildErrors" in arg && arg.allowBuildErrors === true,
|
||
),
|
||
},
|
||
{
|
||
id: "debug.memory.refresh",
|
||
title: "Refresh Memory View",
|
||
category: "Debug",
|
||
icon: "refresh",
|
||
keywords: ["memory", "heap", "instances", "classes"],
|
||
when: "debugHasJvmMemory",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s && sessionSupports("jvmMemory", s)) void refreshMemory(s.id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.heap.capture",
|
||
title: "Capture Heap Snapshot",
|
||
category: "Debug",
|
||
icon: "heap-snapshot",
|
||
keywords: ["memory", "heap", "dump", "snapshot"],
|
||
when: "debugHasJvmMemory",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s && sessionSupports("jvmHeap", s)) void captureHeap(s.id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.dumpThreads",
|
||
title: "Dump Threads",
|
||
category: "Debug",
|
||
icon: "thread-dump",
|
||
keywords: ["thread dump", "jstack", "deadlock", "threads"],
|
||
when: "debugHasJvmMemory",
|
||
indicatesRunning: true,
|
||
run: async () => {
|
||
const s = activeSession();
|
||
if (!s || !sessionSupports("jvmMemory", s)) return;
|
||
const session = s.id;
|
||
const name = s.name;
|
||
// The Run tool window shows the dump; its tab takes the next one through `take` on Refresh.
|
||
await executeAction("run.openThreadDump", {
|
||
title: tx`Threads: ${name}`,
|
||
source: { session },
|
||
take: () => call(commands.debugJvmThreadDump(session)),
|
||
});
|
||
},
|
||
},
|
||
{
|
||
id: "debug.startPageProfile",
|
||
title: "Start CPU Profile",
|
||
description: "Record where the debugged page spends its time",
|
||
category: "Debug",
|
||
icon: "profile",
|
||
keywords: ["profiler", "performance", "flame graph", "browser"],
|
||
when: "debugHasJsPage && !debugPageProfiled",
|
||
run: () => startPageProfile(),
|
||
},
|
||
{
|
||
id: "debug.stopPageProfile",
|
||
title: "Stop CPU Profile",
|
||
description: "Stop recording the page and open the profile",
|
||
category: "Debug",
|
||
icon: "profile",
|
||
keywords: ["profiler", "performance", "flame graph", "browser"],
|
||
when: "debugPageProfiled",
|
||
run: () => stopPageProfile(),
|
||
},
|
||
{
|
||
// The host opens dumps for a trusted project only (F21).
|
||
id: "debug.heap.open",
|
||
title: "Open Heap Dump…",
|
||
category: "Debug",
|
||
icon: "heap-snapshot",
|
||
keywords: ["memory", "heap", "dump", "hprof", "snapshot"],
|
||
when: "projectOpen",
|
||
run: () => openHeapDump(),
|
||
},
|
||
{
|
||
id: "debug.heap.saveDump",
|
||
title: "Save Heap Dump As…",
|
||
category: "Debug",
|
||
icon: "export",
|
||
keywords: ["memory", "heap", "dump", "hprof", "snapshot"],
|
||
when: "debugHeapSnapshotCaptured",
|
||
run: () => {
|
||
const id = activeCapturedSnapshot();
|
||
if (id !== null) return saveHeapDump(id);
|
||
},
|
||
},
|
||
{
|
||
// Runs for the class given as `arg`, else the selected row of the Memory view.
|
||
id: "debug.memory.showInstances",
|
||
title: "Show Instances",
|
||
category: "Debug",
|
||
icon: "list",
|
||
keywords: ["memory", "heap", "objects", "instances"],
|
||
when: "debugSessionPaused",
|
||
run: ({ arg }) => {
|
||
const s = activeSession();
|
||
if (!s || !sessionSupports("jvmInstances", s)) return;
|
||
const name = typeof arg === "string" ? arg : useMemory.getState().bySession[s.id]?.selected;
|
||
if (name) void showInstances(s.id, name);
|
||
},
|
||
},
|
||
{
|
||
// Runs for the class given as `arg`, else the open instances list, else the selected Memory row.
|
||
// Needs only the project's language server, so it also works once the session has ended.
|
||
id: "debug.memory.jumpToSource",
|
||
title: "Jump to Source",
|
||
category: "Debug",
|
||
icon: "edit-source",
|
||
keywords: ["memory", "class", "instances"],
|
||
when: "projectOpen",
|
||
run: ({ arg }) => {
|
||
const s = activeSession();
|
||
const name =
|
||
typeof arg === "string"
|
||
? arg
|
||
: s &&
|
||
(useInstances.getState().bySession[s.id]?.className ?? useMemory.getState().bySession[s.id]?.selected);
|
||
if (name) void jumpToClass(name);
|
||
},
|
||
},
|
||
{
|
||
// Runs for the lead object row of the open instances list.
|
||
id: "debug.memory.showReferrers",
|
||
title: "Show Referrers",
|
||
category: "Debug",
|
||
icon: "hierarchy",
|
||
keywords: ["memory", "instances", "references", "referring objects"],
|
||
when: "debugSessionPaused",
|
||
run: () => {
|
||
const s = activeSession();
|
||
const entry = s && useInstances.getState().bySession[s.id];
|
||
if (!s || !entry?.lead || !sessionSupports("jvmInstances", s) || instancesOutdated(entry, s.stops)) return;
|
||
showReferrers(s.id, entry.lead.key, entry.lead.ref);
|
||
},
|
||
},
|
||
{
|
||
// Closes the pane of the session given as `arg`, else of the active one. No `when`: the pane stays
|
||
// after its session ends and must still close.
|
||
id: "debug.memory.closeInstances",
|
||
title: "Close Instances",
|
||
category: "Debug",
|
||
icon: "close",
|
||
keywords: ["memory", "instances"],
|
||
run: ({ arg }) => {
|
||
const id = typeof arg === "number" ? arg : activeSession()?.id;
|
||
if (id != null && useInstances.getState().bySession[id]) closeInstances(id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.cancelHotSwap",
|
||
title: "Cancel Hot Swap Build",
|
||
description: "Stop the compile a Reload Changed Classes action is waiting on",
|
||
category: "Debug",
|
||
icon: "stop",
|
||
when: "debugHotSwapBuilding",
|
||
run: () => cancelHotSwapBuild(),
|
||
},
|
||
{
|
||
id: "debug.rerun",
|
||
title: "Rerun",
|
||
category: "Debug",
|
||
icon: "rerun",
|
||
when: "debugCanRerun",
|
||
// ⌘R / Ctrl+F5 rerun only in the Debug tool window (⌘R is Replace in the editor).
|
||
keyWhen: "activeToolWindow == 'debug'",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s) void rerunSession(rootOf(s).id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.resume",
|
||
title: "Resume Program",
|
||
category: "Debug",
|
||
icon: "resume",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (t)
|
||
void report(
|
||
tx("Resume failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugResume(t.s.id, t.thread))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.pause",
|
||
title: "Pause Program",
|
||
category: "Debug",
|
||
icon: "pause",
|
||
// The trace resumes the program itself; a pause would suspend threads under the running trace.
|
||
when: "debugSessionRunning && !debugStreamTracing",
|
||
run: async () => {
|
||
const s = activeSession();
|
||
if (!s || s.status !== "running") return;
|
||
let thread = s.selectedThread ?? s.threads[0]?.id;
|
||
if (thread == null) {
|
||
const threads = await call(commands.debugThreads(s.id)).catch(() => []);
|
||
thread = threads[0]?.id ?? 0;
|
||
}
|
||
await report(tx("Pause failed"), call(commands.debugPause(s.id, thread)));
|
||
},
|
||
},
|
||
{
|
||
id: "debug.hotReload",
|
||
title: "Hot Reload",
|
||
category: "Debug",
|
||
icon: "hot-reload",
|
||
description: "Flutter: inject the changed sources into the running app",
|
||
when: "debugSessionRunning && debugSessionDart",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s) void report("Hot Reload failed", call(commands.debugHotReload(s.id, "manual")));
|
||
},
|
||
},
|
||
{
|
||
id: "debug.hotRestart",
|
||
title: "Hot Restart",
|
||
category: "Debug",
|
||
icon: "refresh",
|
||
description: "Flutter: restart the app, discarding its state",
|
||
when: "debugSessionRunning && debugSessionDart",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s) void report("Hot Restart failed", call(commands.debugHotRestart(s.id)));
|
||
},
|
||
},
|
||
{
|
||
id: "debug.openDevTools",
|
||
title: "Open Flutter DevTools in Browser",
|
||
category: "Debug",
|
||
icon: "external-link",
|
||
description: "Flutter: inspect the running app in the browser",
|
||
when: "debugHasVmService",
|
||
run: () => {
|
||
const s = activeSession();
|
||
const uri = s && rootOf(s).vmServiceUri;
|
||
if (uri) void report("Couldn't open Flutter DevTools", openDevTools(uri));
|
||
},
|
||
},
|
||
{
|
||
id: "debug.refreshDevTools",
|
||
title: "Refresh Flutter DevTools",
|
||
category: "Debug",
|
||
icon: "refresh",
|
||
description: "Flutter: load the DevTools page again",
|
||
when: "flutterDevTools",
|
||
run: (c) => {
|
||
const id = c.arg;
|
||
for (const w of DEVTOOLS_WINDOWS) if (!id || id === w.id) refreshDevTools(w.id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.refreshWidgetPreview",
|
||
title: "Refresh Flutter Widget Preview",
|
||
category: "Debug",
|
||
icon: "refresh",
|
||
description: "Flutter: load the Widget Preview page again",
|
||
when: "flutterDevTools",
|
||
run: () => refreshDevTools(WIDGET_PREVIEW_WINDOW),
|
||
},
|
||
step("debug.stepOver", "Step Over", "over", "step-over"),
|
||
step("debug.stepInto", "Step Into", "into", "step-into"),
|
||
step("debug.stepOut", "Step Out", "out", "step-out"),
|
||
stepInstruction("debug.stepOverInstruction", "Step Over Instruction", "over", "step-over"),
|
||
stepInstruction("debug.stepIntoInstruction", "Step Into Instruction", "into", "step-into"),
|
||
{
|
||
// The Frames list passes the frame; without one, the selected frame.
|
||
id: "debug.showDisassembly",
|
||
title: "Show Disassembly",
|
||
category: "Debug",
|
||
keywords: ["assembly", "instructions", "machine code", "asm", "program counter"],
|
||
when: "debugSessionActive",
|
||
run: ({ arg }) => showDisassembly(arg),
|
||
},
|
||
{
|
||
id: "debug.forceStepOver",
|
||
title: "Force Step Over",
|
||
category: "Debug",
|
||
icon: "force-step-over",
|
||
description: "Step over, ignoring breakpoints in the called code",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (t)
|
||
void report(
|
||
tx("Force Step Over failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugForceStepOver(t.s.id, t.thread))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
// DAP has no "ignore stepping filters" flag: adapters step into what their
|
||
// launch options (justMyCode, skipFiles, stepFilters) allow.
|
||
id: "debug.forceStepInto",
|
||
title: "Force Step Into",
|
||
category: "Debug",
|
||
icon: "force-step-into",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (t)
|
||
void report(
|
||
tx("Force Step Into failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugStep(t.s.id, t.thread, "into"))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.smartStepInto",
|
||
title: "Smart Step Into",
|
||
category: "Debug",
|
||
icon: "smart-step-into",
|
||
description: "Choose which call on the current line to step into",
|
||
when: paused,
|
||
run: () => void report(tx("Smart Step Into failed"), smartStepInto()),
|
||
},
|
||
{
|
||
id: "debug.showExecutionPoint",
|
||
title: "Show Execution Point",
|
||
category: "Debug",
|
||
icon: "show-execution-point",
|
||
when: "debugSessionPaused",
|
||
run: () => {
|
||
const s = activeSession();
|
||
if (s) void showExecutionPoint(s.id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.resetFrame",
|
||
title: "Reset Frame",
|
||
category: "Debug",
|
||
icon: "reset-frame",
|
||
keywords: ["drop frame", "pop frame", "restart frame"],
|
||
description: "Return to the start of the selected frame's method",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
const frame = t && selectedFrame(t.s);
|
||
if (!t || !frame) return;
|
||
if (!sessionSupports("restartFrame", t.s)) {
|
||
notSupported("Reset Frame", t.s);
|
||
return;
|
||
}
|
||
void report(
|
||
tx("Reset Frame failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugRestartFrame(t.s.id, frame.id))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.setValue",
|
||
title: "Set Value…",
|
||
category: "Debug",
|
||
icon: "edit",
|
||
keyWhen: "debugVariablesFocus",
|
||
when: paused,
|
||
run: () => focusedDebugView()?.setValue?.(),
|
||
},
|
||
{
|
||
id: "debug.jumpToSource",
|
||
title: "Jump to Source",
|
||
category: "Debug",
|
||
keyWhen: "debugFramesFocus || debugVariablesFocus",
|
||
when: "debugSessionPaused",
|
||
run: () => {
|
||
const view = focusedDebugView();
|
||
if (view?.jumpToSource) {
|
||
view.jumpToSource();
|
||
return;
|
||
}
|
||
const s = activeSession();
|
||
const frame = s && selectedFrame(s);
|
||
if (frame) void revealFrame(frame, true);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.attachToProcess",
|
||
title: "Attach to Process…",
|
||
category: "Debug",
|
||
icon: "attach-to-process",
|
||
description: "Attach the debugger to a running Java, Node.js, Python, Go or native process",
|
||
run: () => void openAttachPopup(),
|
||
},
|
||
{
|
||
id: "debug.attachUnity",
|
||
title: "Attach to Unity Process",
|
||
category: "Run",
|
||
icon: "debug",
|
||
hidden: true,
|
||
when: "projectOpen",
|
||
run: ({ arg }) => openAttachPopup("unity", arg as RunConfig | undefined),
|
||
},
|
||
{
|
||
id: "debug.debugInBrowser",
|
||
title: "Debug in Browser",
|
||
category: "Debug",
|
||
icon: "browser-chrome",
|
||
description: "Opens a URL in Chrome or Edge with the debugger attached (arg: the URL).",
|
||
hidden: true,
|
||
run: ({ arg }) => void debugInBrowser(arg),
|
||
},
|
||
{
|
||
id: "debug.runToCursor",
|
||
title: "Run to Cursor",
|
||
category: "Debug",
|
||
icon: "run-to-cursor",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
const c = cursor();
|
||
if (t && c && breakpointPathAllowed(c.path))
|
||
void report(
|
||
tx("Run to Cursor failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugRunTo(t.s.id, t.thread, c.path, c.line, false))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.forceRunToCursor",
|
||
title: "Force Run to Cursor",
|
||
category: "Debug",
|
||
icon: "force-run-to-cursor",
|
||
description: "Run to the caret, ignoring breakpoints on the way",
|
||
when: paused,
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
const c = cursor();
|
||
if (t && c && breakpointPathAllowed(c.path))
|
||
void report(
|
||
tx("Force Run to Cursor failed"),
|
||
resumeExecution(t.s.id, () => call(commands.debugRunTo(t.s.id, t.thread, c.path, c.line, true))),
|
||
);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.toggleBreakpoint",
|
||
title: "Toggle Line Breakpoint",
|
||
category: "Debug",
|
||
icon: "breakpoint",
|
||
run: () => {
|
||
const c = cursor();
|
||
if (!c || !breakpointPathAllowed(c.path)) return;
|
||
const exists = useBreakpoints.getState().byFile[c.path]?.some((b) => b.line === c.line);
|
||
const language = activeEditor()?.ctx.language ?? "";
|
||
if (!exists && !canPlaceBreakpoint(language, c.path)) {
|
||
notifications().notify({
|
||
level: "info",
|
||
key: "debug.breakpointNotAllowed",
|
||
title: "Breakpoints can't be placed in this file",
|
||
body: "Enable Settings › Build, Execution, Deployment › Debugger › Allow placing breakpoints in any file.",
|
||
});
|
||
return;
|
||
}
|
||
const ed = activeEditor();
|
||
// Like IDEA, no new breakpoint on a blank or comment-only line; an existing one still goes.
|
||
const taken = exists || specialAt(c.path).some((b) => b.line === c.line);
|
||
if (!taken && ed && !lineHasCode(ed.view.state, c.line)) return;
|
||
if (ed) toggleBreakpointSmart(c.path, c.line, language, ed.view.state.doc.toString());
|
||
else toggleBreakpoint(c.path, c.line);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.toggleTemporaryBreakpoint",
|
||
title: "Toggle Temporary Line Breakpoint",
|
||
category: "Debug",
|
||
icon: "breakpoint",
|
||
description: "A line breakpoint that is removed after it is hit",
|
||
run: () => {
|
||
const c = cursor();
|
||
const ed = activeEditor();
|
||
if (!c || !breakpointPathAllowed(c.path) || !canPlaceBreakpoint(ed?.ctx.language ?? "", c.path)) return;
|
||
const exists = useBreakpoints.getState().byFile[c.path]?.some((b) => b.line === c.line);
|
||
if (!exists && ed && !lineHasCode(ed.view.state, c.line)) return;
|
||
toggleTemporaryBreakpoint(c.path, c.line);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.toggleMethodBreakpoint",
|
||
title: "Toggle Method Breakpoint",
|
||
category: "Debug",
|
||
icon: "breakpoint-method",
|
||
run: () => {
|
||
const ed = activeEditor();
|
||
const c = cursor();
|
||
if (!ed || !c || !breakpointPathAllowed(c.path)) return;
|
||
const existing = specialAt(c.path).find((b) => b.kind === "method" && b.line === c.line);
|
||
const method = methodAt(ed.ctx.language, ed.view.state.doc.toString(), c.line);
|
||
if (!existing && !method) {
|
||
notifications().notify({
|
||
level: "info",
|
||
key: "debug.noMethod",
|
||
title: "No method declaration on this line",
|
||
body: "Put the caret on a method declaration, or add a method breakpoint by name in View Breakpoints.",
|
||
});
|
||
return;
|
||
}
|
||
toggleMethodAt(c.path, c.line, method?.name ?? "");
|
||
},
|
||
},
|
||
{
|
||
id: "debug.toggleFieldWatchpoint",
|
||
title: "Toggle Field Watchpoint",
|
||
category: "Debug",
|
||
icon: "breakpoint-field",
|
||
run: () => {
|
||
const ed = activeEditor();
|
||
const c = cursor();
|
||
if (!ed || !c || !breakpointPathAllowed(c.path)) return;
|
||
const existing = specialAt(c.path).find((b) => b.kind === "field" && b.line === c.line);
|
||
const field = fieldAt(ed.ctx.language, ed.view.state.doc.toString(), c.line);
|
||
if (!existing && !field) {
|
||
notifications().notify({
|
||
level: "info",
|
||
key: "debug.noField",
|
||
title: "No field declaration on this line",
|
||
body: "Field watchpoints can be set on Java field declarations, or from the Variables view while suspended.",
|
||
});
|
||
return;
|
||
}
|
||
toggleFieldAt(c.path, c.line, field ?? { dataId: "", label: "" });
|
||
},
|
||
},
|
||
{
|
||
id: "debug.toggleBreakpointEnabled",
|
||
title: "Toggle Breakpoint Enabled",
|
||
category: "Debug",
|
||
icon: "breakpoint",
|
||
keywords: ["enable", "disable"],
|
||
enabled: () => {
|
||
const at = breakpointsOnCaretLines();
|
||
return !!at && at.lines.length + at.special.length > 0;
|
||
},
|
||
run: () => {
|
||
const at = breakpointsOnCaretLines();
|
||
if (!at) return;
|
||
for (const b of at.lines) updateBreakpoint(at.path, b.id, { enabled: !b.enabled });
|
||
for (const b of at.special) updateSpecial(b.id, { enabled: !b.enabled });
|
||
},
|
||
},
|
||
{
|
||
id: "debug.viewBreakpoints",
|
||
title: "View Breakpoints…",
|
||
category: "Debug",
|
||
icon: "breakpoint",
|
||
run: () => {
|
||
const c = cursor();
|
||
const bp = c ? useBreakpoints.getState().byFile[c.path]?.find((b) => b.line === c.line) : undefined;
|
||
openBreakpointsDialog(c && bp ? { path: c.path, id: bp.id } : undefined);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.muteBreakpoints",
|
||
title: "Mute Breakpoints",
|
||
category: "Debug",
|
||
keywords: ["unmute", "disable all"],
|
||
toggled: () => useBreakpoints.getState().muted,
|
||
run: () => setMuted(!useBreakpoints.getState().muted),
|
||
},
|
||
{
|
||
id: "debug.removeAllBreakpoints",
|
||
title: "Remove All Breakpoints",
|
||
category: "Debug",
|
||
run: () => {
|
||
removeAllBreakpoints();
|
||
removeAllSpecial();
|
||
removeAllExceptionClasses();
|
||
},
|
||
},
|
||
{
|
||
id: "debug.removeAllBreakpointsInFile",
|
||
title: "Remove All Breakpoints In The Current File",
|
||
category: "Debug",
|
||
run: () => {
|
||
const path = activeEditor()?.ctx.path;
|
||
if (!path) return;
|
||
removeFileBreakpoints(path);
|
||
removeSpecialIn(path);
|
||
},
|
||
},
|
||
{
|
||
// Variables and watches pass their memory reference; without one the Memory View opens on its address field.
|
||
id: "debug.viewMemory",
|
||
title: "View Memory",
|
||
category: "Debug",
|
||
keywords: ["memory", "hex", "bytes", "address", "pointer", "dump"],
|
||
when: "debugSessionActive",
|
||
run: ({ arg }) => viewMemory(arg),
|
||
},
|
||
{
|
||
id: "debug.evaluate",
|
||
title: "Evaluate Expression…",
|
||
category: "Debug",
|
||
when: "debugSessionActive",
|
||
run: () => openEvaluateDialog(evaluateSeed()),
|
||
},
|
||
{
|
||
id: "debug.traceStreamChain",
|
||
title: "Trace Stream Chain",
|
||
category: "Debug",
|
||
icon: "stream-trace",
|
||
keywords: ["stream", "chain", "trace", "java"],
|
||
when: "debugCanTraceStream",
|
||
run: () => {
|
||
const t = pausedTarget();
|
||
if (t) void report(tx("Trace Stream Chain failed"), traceStreamChain(t.s.id));
|
||
},
|
||
},
|
||
{
|
||
// The trace tab passes its session as `arg`.
|
||
id: "debug.streamTrace.stopRecording",
|
||
title: "Stop Recording",
|
||
category: "Debug",
|
||
keywords: ["stream", "trace"],
|
||
when: "debugAnyStreamTracing",
|
||
enabled: ({ arg }) => {
|
||
const id = traceTarget(arg);
|
||
return id != null && isTracing(id) && !useStreamTrace.getState().bySession[id]?.stoppedRecording;
|
||
},
|
||
run: ({ arg }) => {
|
||
const id = traceTarget(arg);
|
||
if (id != null) stopRecording(id);
|
||
},
|
||
},
|
||
{
|
||
id: "debug.streamTrace.abort",
|
||
title: "Abort Operation…",
|
||
category: "Debug",
|
||
keywords: ["stream", "trace", "cancel"],
|
||
when: "debugAnyStreamTracing",
|
||
enabled: ({ arg }) => {
|
||
const id = traceTarget(arg);
|
||
return id != null && isTracing(id);
|
||
},
|
||
run: ({ arg }) => {
|
||
const id = traceTarget(arg);
|
||
if (id != null) useOverlays.setState({ streamAbort: id });
|
||
},
|
||
},
|
||
{
|
||
id: "debug.browseConsoleHistory",
|
||
title: "Browse Console History",
|
||
category: "Debug",
|
||
keywords: ["history", "previous expressions", "repl"],
|
||
when: "debugSessionActive",
|
||
run: () => {
|
||
if (!browseFocusedConsoleHistory()) showStatusInfo(tx("Focus the debug console input first"));
|
||
},
|
||
},
|
||
{
|
||
// ⌥⌘F8: the selection (or expression at the caret) evaluated in a value hint, no dialog.
|
||
id: "debug.quickEvaluate",
|
||
title: "Quick Evaluate Expression",
|
||
category: "Debug",
|
||
when: "debugSessionPaused && textEditorActive",
|
||
run: ({ arg }) => quickEvaluate(arg),
|
||
},
|
||
{
|
||
id: "debug.showToolWindow",
|
||
title: "Show Debug Tool Window",
|
||
category: "Debug",
|
||
hidden: true,
|
||
run: () => toolWindowService().show("debug", true),
|
||
},
|
||
]);
|
||
}
|