Skip to content

DAP: bring the Debugger/Variables tab to the front when the program stops, not only at a line breakpoint #2003

Closed

Description

@muescha

What happens

When a DAP program stops, the Debug tool window often stays on the Console tab. You have to click the Debugger tab (new UI) or the Variables tab (classic UI) yourself to see the variables. The Java debugger brings that tab to the front when a breakpoint stops the program.

Why

Claude Code looked through the LSP4IJ code on main (21a3f42) and the IntelliJ 2024.2 sources and found two reasons.

1. Most stops don't ask IntelliJ to bring a tab to the front.

IntelliJ brings the tab to the front only when the session is told to "attract" the user:

  • XDebugSession.breakpointReached(...) stops with attract = true. XDebugSessionImpl then brings the Debug tool window to the front (when "Show debug window on breakpoint" is on), and calls attractBy("breakpoint"), which selects the tab registered for the breakpoint condition: "DebuggerView" in the new UI (XDebugSessionTab3), FRAME_CONTENT in the classic UI (DebuggerSessionTabBase).
  • XDebugSession.positionReached(context) stops with attract = false. It does not bring any tab to the front.

In DAPClient.suspend, LSP4IJ calls breakpointReached only when getStopBreakpoint finds an IntelliJ breakpoint: by the hitBreakpointIds of the stopped event, or, without ids, by the line of the top frame. For every other stop it calls getSession().positionReached(context), so the tab stays where it is. That covers these stops:

Steps also go through positionReached. That is correct, as IntelliJ never moves the focus on a step.

2. IntelliJ selects the tab only once per session.

The platform registers the breakpoint attraction with LayoutAttractionPolicy.FocusOnce. The first breakpoint of a session selects the tab. After that IntelliJ only makes the tab bounce. If you click the Console once, it stays in front for the rest of the session. The Java debugger behaves the same way, so this part is platform behaviour, not an LSP4IJ bug.

Workaround without a code change

Users can already choose which tab IntelliJ selects when a breakpoint stops the program:

  1. In the Debug tool window, right-click the tab header of Debugger (new UI) or Variables (classic UI).
  2. Turn on Focus on Breakpoint.

IntelliJ saves this choice for the debugger layout, so it also applies to later sessions. Two limits remain:

  • It only works for stops that LSP4IJ reports with breakpointReached (reason 1). Exceptions, pause and the other stops listed above still leave the Console in front.
  • IntelliJ still selects the tab only at the first breakpoint of a session (reason 2).

Possible changes (for the maintainers to decide)

A. Attract the user for every stop caused by a breakpoint, as the Java debugger does.

In JavaDebugProcess (2024.2), every stop caused by a breakpoint calls XDebugSessionImpl.breakpointReachedNoProcessing(...), which stops with attract = true. That includes line breakpoints and also exception breakpoints, method breakpoints and field watchpoints, because in Java they are all XBreakpoints. Every other stop (a step, or a pause the user started) calls positionReached(context) and doesn't bring a tab to the front.

To match it, DAPClient.suspend would attract the user when the stopped reason is breakpoint, exception, function breakpoint, data breakpoint or instruction breakpoint, and not for step, goto, pause and entry:

    /**
     * Returns whether the reason of a 'stopped' event is a breakpoint of any kind, which brings the
     * Debugger/Variables tab to the front, as in the Java debugger.
     *
     * @param reason the reason of the 'stopped' event.
     * @return true if a breakpoint of any kind stopped the program and false otherwise.
     */
    static boolean isBreakpointReason(@Nullable String reason) {
        return StoppedEventArgumentsReason.BREAKPOINT.equals(reason)
                || StoppedEventArgumentsReason.EXCEPTION.equals(reason)
                || StoppedEventArgumentsReason.FUNCTION_BREAKPOINT.equals(reason)
                || StoppedEventArgumentsReason.DATA_BREAKPOINT.equals(reason)
                || StoppedEventArgumentsReason.INSTRUCTION_BREAKPOINT.equals(reason);
    }

There are two ways to attract the user, since the public XDebugSession has only positionReached(context):

  • A1, the same as breakpointReached: call XDebugSessionImpl.positionReached(context, true). That method is not in the XDebugSession interface. LSP4IJ already reaches such methods by reflection in BreakpointInternalSupport, so it could go there, with positionReached(context) as the fallback. It also brings the Debug tool window to the front, as a breakpoint does.
  • A2, public API only: keep positionReached(context), and then call getSession().getUI().attractBy("breakpoint") on the EDT (XDebuggerUIConstants.LAYOUT_VIEW_BREAKPOINT_CONDITION). This selects the same tab with the same FocusOnce policy, but it doesn't bring the Debug tool window to the front.

A stop at a breakpoint that LSP4IJ finds still goes through breakpointReached as before, so nothing changes there.

Open questions:

  • entry (stop on entry) isn't a breakpoint in DAP, but users ask for it in the launch configuration, much like a breakpoint on the first line. Should it bring the tab to the front too? The Java debugger has no such stop to compare with.
  • Some adapters send a reason that isn't in the DAP list. Should those stops stay without attracting, as they are now?

B. Optional: select the tab at every stop, not only at the first one.

In createTabLayouter().registerAdditionalContent(ui), LSP4IJ could register its own policy:

ui.getDefaults().initContentAttraction(
        debuggerContentId, // "DebuggerView" in the new UI, DebuggerContentInfo.FRAME_CONTENT or VARIABLES_CONTENT in the classic UI
        "breakpoint",      // XDebuggerUIConstants.LAYOUT_VIEW_BREAKPOINT_CONDITION
        new LayoutAttractionPolicy.FocusAlways());

A tab the user picked with Focus on Breakpoint would still win, because RunnerLayout.getToFocus reads the user's choice first; only the policy would change.

Downsides:

  • It differs from the platform default and from the Java debugger.
  • It can be annoying when you want to keep watching the Console while the program hits breakpoints.
  • XDebuggerUIConstants and the "DebuggerView" id are internal to the platform, so the strings would have to be used as they are and may change.

If B is wanted, it could also be a setting rather than a fixed behaviour.

C. Change nothing and document Focus on Breakpoint.

Recommendation

Claude Code recommends A, and not B by default:

  • A makes DAP behave like the Java debugger: every stop caused by a breakpoint, of any kind, brings the Debugger/Variables tab to the front once per session, and later ones make it bounce. Steps and pauses leave the tabs alone. Users of both debuggers get the same behaviour.
  • A is a small change in one method. A1 matches a breakpoint exactly but needs the internal XDebugSessionImpl method (by reflection, as LSP4IJ already does for other breakpoint calls). A2 uses only public API but leaves the Debug tool window where it is.
  • The workaround above then covers every kind of breakpoint, not only line breakpoints.
  • B changes platform behaviour and relies on internal ids. If users ask for it, it fits better as an opt-in setting on top of A.

The maintainers may see this differently, for example if some debug adapters send pause or entry stops that nobody wants to be interrupted by.

How this was checked

  • LSP4IJ: read DAPClient.suspend, getStopBreakpoint, BreakpointInternalSupport and DAPDebugProcess.createTabLayouter on main at 21a3f42.
  • IntelliJ: read the 2024.2 sources and bytecode: XDebugSession (only positionReached(XSuspendContext)), XDebugSessionImpl.positionReached(XSuspendContext, boolean), breakpointReached, breakpointReachedNoProcessing and positionReachedInternal (tool window to the front, attractBy("breakpoint")), RunnerLayoutUi.attractBy, JavaDebugProcess (how the Java debugger reports a stop), XDebugSessionTab3, DebuggerSessionTabBase, LayoutAttractionPolicy.FocusOnce, RunnerLayout.getToFocus and getAttractionPolicy, and FocusOnBreakpointAction.
  • Not checked at runtime yet, and not checked against newer IntelliJ versions.

Activity

  1. added a commit that references this issue on Nov 21, 2026
    e8fbbd5
  2. added this to the 0.30.2 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions