Skip to content

fix(dap): bring the debugger to the front when any kind of breakpoint stops the program - #2004

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
muescha:fix/dap-focus-debugger-tab-on-stop
Nov 20, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
muescha:fix/dap-focus-debugger-tab-on-stop

Conversation

@muescha

@muescha muescha commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #2003

Summary

When a DAP program stops and LSP4IJ doesn't find an IntelliJ breakpoint for the stop, it reports the stop with XDebugSession.positionReached(context). That never attracts the user, so the Debug tool window stays on the Console tab. This happens for exceptions, and for function and data breakpoints when the adapter sends no hitBreakpointIds.

With this change, a stop whose reason says that a breakpoint of any kind stopped the program brings the debugger to the front, as an IntelliJ breakpoint does. Steps, pauses and stops on entry are unchanged.

Changes

  • DAPClient.isBreakpointReason(reason) (new): breakpoint, exception, function breakpoint, data breakpoint and instruction breakpoint are breakpoint reasons; step, goto, pause, entry, unknown reasons and none are not.
  • DAPClient.positionReached(session, context, reason) (new), used by suspend where it called positionReached(context) before:
    • Without a breakpoint reason: session.positionReached(context), as before.
    • With a breakpoint reason: XDebugSessionImpl.positionReached(context, true), called by reflection through BreakpointInternalSupport. This is what breakpointReached does: it brings the Debug tool window to the front (when "Show debug window on breakpoint" is on) and selects the Debugger tab (Variables in the classic UI).
    • If that method is missing, or the session is not an XDebugSessionImpl: session.positionReached(context), then session.getUI().attractBy("breakpoint") on the EDT. This selects the tab but doesn't bring the tool window to the front.
  • A stop that LSP4IJ matches to an IntelliJ breakpoint still goes through breakpointReached, so nothing changes there.
  • BreakpointInternalSupport is now public (@ApiStatus.Internal), since DAPClient is in another package, with the new public method positionReached(XDebugSession, XSuspendContext, boolean). There is still no compile-time dependency on XDebugSessionImpl. The method exists in 2024.2 (the lowest supported version) and in 2026.3.

IntelliJ still selects the tab only at the first breakpoint of a session (LayoutAttractionPolicy.FocusOnce); later stops make it bounce. This is the same as in the Java debugger, and this PR doesn't change it (variant B in #2003).

Open questions

  • entry (stop on entry) doesn't attract the user. It 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 attract too?
  • Reasons that DAP doesn't define don't attract, as before. Some adapters send their own reasons; should some of them attract?

Tests

  • DAPClientAttractOnStopTest:
    • Which reasons are breakpoint reasons, and which are not (including null and an unknown reason).
    • An exception stop on a session that is not an XDebugSessionImpl calls positionReached(context), then attractBy("breakpoint").
    • A step, a pause and an entry stop only call positionReached(context).
    • XDebugSessionImpl.positionReached(XSuspendContext, boolean) exists on the platform of the tests.
    • BreakpointInternalSupport.positionReached leaves a session that is not an XDebugSessionImpl to the caller.

The call with attract = true on a real XDebugSessionImpl is not covered by a unit test; it is checked in the IDE below.

./gradlew test --tests 'com.redhat.devtools.lsp4ij.dap.*': 332 tests, all pass. ./gradlew buildPlugin: passes.

Checked in the IDE

Claude Code ran runIde (IntelliJ IDEA Community 2024.2 sandbox) and debugged this script with the debugpy bundled in IntelliJ IDEA 2026.3, with the Console tab in front:

import time


def work(n):
    total = 0
    for i in range(n):
        total += i
        print("step", i)
        time.sleep(1)
    return total


def fail():
    raise ValueError("bad value")


print("total", work(30))
fail()

On main, the uncaught ValueError stops the program (reason exception), but the Console stays in front:

main: exception stop, Console stays in front

With this PR, the same stop selects the Threads & Variables tab:

This PR: exception stop selects Threads & Variables

A line breakpoint still selects the tab, as before:

This PR: line breakpoint selects Threads & Variables

After selecting the Console again, a step over leaves it in front:

This PR: step over keeps the Console in front

Not checked: pause. This sandbox offered no Pause action for the session. The code path is the same as for a step, and the unit test covers it.

Relation to #2002

#2002 (for #1999) changes one line of DAPClient.suspend (the lookup of the breakpoint on the line). This PR changes the positionReached call further down. The change applies cleanly on top of #2002.

🤖 Generated with Claude Code

… stops the program

A stop which LSP4IJ doesn't match to an IntelliJ breakpoint, such as an
exception, or a function or data breakpoint without hitBreakpointIds, was
reported with positionReached(context), which never attracts the user. Now
a stop whose reason is breakpoint, exception, function breakpoint, data
breakpoint or instruction breakpoint calls
XDebugSessionImpl.positionReached(context, true) by reflection, as
breakpointReached does. Without that method, the session is told with
positionReached(context) and the Debugger tab is selected with
attractBy("breakpoint"). Steps, pauses and stops on entry are unchanged.

Fixes redhat-developer#2003

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • The Debugger tab now comes to the front when execution stops because of a breakpoint, including exception, function, data, and instruction breakpoints.
    • Stops caused by stepping, pausing, or entering the program do not switch the active tab.

For stops without a matched IntelliJ breakpoint, DAPClient now attracts the debugger for breakpoint-related reasons. Other stop reasons use regular session positioning. Tests cover reason classification, tab selection, and reflective support.

Changes: DAP breakpoint stop attraction

Layer / File(s) Summary
Reflective session positioning
src/main/java/com/redhat/devtools/lsp4ij/dap/breakpoints/BreakpointInternalSupport.java
The internal support class is public and marked @ApiStatus.Internal. It looks up XDebugSessionImpl.positionReached(XSuspendContext, boolean) and exposes a wrapper that reports whether reflective positioning was handled.
Stop routing and validation
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientAttractOnStopTest.java
For stops without a matched IntelliJ breakpoint, DAPClient uses reflective positioning for breakpoint, exception, function-breakpoint, data-breakpoint, and instruction-breakpoint reasons. Other reasons use regular positioning. Tests check reason classification, debugger-tab selection, and reflective support behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DAPClient
  participant BreakpointInternalSupport
  participant XDebugSessionImpl
  participant XDebugSession
  participant DebuggerUI
  DAPClient->>BreakpointInternalSupport: Try positionReached for a breakpoint reason
  alt Internal positioning succeeds
    BreakpointInternalSupport->>XDebugSessionImpl: Invoke positionReached(context, true)
  else Internal positioning unavailable
    DAPClient->>XDebugSession: Call regular positionReached(context)
    DAPClient->>DebuggerUI: Schedule Debugger-tab selection when session is active
  end
Loading

Suggested reviewers: lagergren, angelozerr

Merge Risk: Minimal · up to 58155

This change brings the debugger to the front when exception, function, data or instruction breakpoints stop a DAP session without a matched IntelliJ breakpoint. Other stop reasons behave as before. No concrete defect was established. The reflective call into an internal IntelliJ API is only partly covered by tests, so a quick manual check on the supported IDE versions is advisable.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: stops caused by any breakpoint kind (breakpoint, exception, function, data, instruction) now bring the debugger to the front. The raw summary, the PR objectives, and t…
Description check Passed The description is detailed and on-topic. It explains the problem (exception and function/data breakpoint stops leave the Console tab in front), the new isBreakpointReason and positionReached helpers,…
Linked Issues check Passed Linked issue #2003 is the only direct target. Its coding requirements are: (1) attract the Debugger/Variables tab for breakpoint, exception, function breakpoint, data breakpoint and instruction breakp…
Out of Scope Changes check Passed All changes connect to #2003. BreakpointInternalSupport is made public and annotated @ApiStatus.Internal, and gains a public positionReached wrapper. This is needed because DAPClient lives in a differ…
Full details: Title check

Explanation

The title names the main change: stops caused by any breakpoint kind (breakpoint, exception, function, data, instruction) now bring the debugger to the front. The raw summary, the PR objectives, and the linked issue #2003 all describe this change. The title follows a conventional-commit style and is specific.

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the problem (exception and function/data breakpoint stops leave the Console tab in front), the new isBreakpointReason and positionReached helpers, the reflection call to XDebugSessionImpl.positionReached(context, true) with a fallback, the BreakpointInternalSupport visibility change, the tests, and IDE verification. It matches the raw summary and objectives.

Full details: Linked Issues check

Explanation

Linked issue #2003 is the only direct target. Its coding requirements are: (1) attract the Debugger/Variables tab for breakpoint, exception, function breakpoint, data breakpoint and instruction breakpoint stops that LSP4IJ does not match to an IntelliJ breakpoint; (2) leave step, goto, pause and entry stops unchanged; (3) use XDebugSessionImpl.positionReached(XSuspendContext, boolean) with a fallback. The raw summary of the whole-PR diff (merge base 21a3f42 to head 58155b1) shows: DAPClient.isBreakpointReason classifies the five breakpoint reasons as breakpoint stops and all others as non-breakpoint stops. DAPClient.positionReached routes breakpoint stops to BreakpointInternalSupport.positionReached(session, context, true), and other stops to session.positionReached(context). The fallback calls positionReached(context) then attractBy("breakpoint") on the EDT. Stops matched to a breakpoint still call breakpointReached. Unit tests in DAPClientAttractOnStopTest cover reason classification, the fallback, and the non-attracting reasons. The attract=true path on a real XDebugSessionImpl is verified only by the author's IDE run, as the PR states. This is a test-coverage gap, not a missing requirement. The issue's open questions (entry, adapter-specific reasons, FocusOnce policy) are not required by the issue's proposed scope and are correctly left unchanged. Inspection was limited to the PR description, issue text, and the raw diff summary; no source file was read directly.

Full details: Out of Scope Changes check

Explanation

All changes connect to #2003. BreakpointInternalSupport is made public and annotated @ApiStatus.Internal, and gains a public positionReached wrapper. This is needed because DAPClient lives in a different package and calls the helper. The DAPClient.suspend change replaces the direct positionReached call, which is the requested behavior. DAPClientAttractOnStopTest supports the new logic. The PR description and the issue's proposed design (option A1) are consistent with the code summary. No unrelated files or behavior changes appear in the summary. The reflective call's handling (returning true on InvocationTargetException) is an implementation detail tied to the requested attraction behavior and does not add unrelated scope. Inspection was limited to the raw diff summary; no source file was read directly.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4dc2657b-ca3f-4558-8001-21f37ffa8484
Commits

Reviewing files that changed from the base of the PR and between 21a3f42 and 58155b1.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/dap/breakpoints/BreakpointInternalSupport.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientAttractOnStopTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.61290% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.12%. Comparing base (21a3f42) to head (58155b1).

Files with missing lines Patch % Lines
...4ij/dap/breakpoints/BreakpointInternalSupport.java 23.07% 8 Missing and 2 partials ⚠️
...m/redhat/devtools/lsp4ij/dap/client/DAPClient.java 72.22% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2004      +/-   ##
==========================================
- Coverage   49.13%   49.12%   -0.01%     
==========================================
  Files         812      812              
  Lines       32975    33005      +30     
  Branches     5101     6747    +1646     
==========================================
+ Hits        16201    16213      +12     
- Misses      14234    14249      +15     
- Partials     2540     2543       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@muescha

muescha commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren lagergren added this to the 0.31.0 milestone Nov 17, 2026
@lagergren

Copy link
Copy Markdown
Collaborator

@muescha Thanks for the PR, and for laying out the options in #2003.

We'd like to take this in 0.31.0 rather than in 0.30.0:

  • It isn't a regression. LSP4IJ brings the Debugger tab to the front only for stops it reports with breakpointReached, and 0.21.0 does the same, so 0.30.0 changes nothing here.
  • It changes what users see at every stop for an exception and a function, data or instruction breakpoint. It does that through IntelliJ's internal XDebugSessionImpl.positionReached(XSuspendContext, boolean), called by reflection with a fallback, and it makes BreakpointInternalSupport public (marked @ApiStatus.Internal). That's a change in behavior and in the use of internal API that we'd rather not make right before a release.
  • DAP: bring the Debugger/Variables tab to the front when the program stops, not only at a line breakpoint #2003 leaves the choice between A, A1 and A2 to the maintainers. @angelozerr, which one would you like?

I've set the milestone to 0.31.0.

@lagergren lagergren modified the milestones: 0.31.0, 0.30.2 Nov 20, 2026
@lagergren
lagergren merged commit e8fbbd5 into redhat-developer:main Nov 20, 2026
9 checks passed
@lagergren

Copy link
Copy Markdown
Collaborator

@muescha Thanks for this, and for laying out the options in #2003. Merged for 0.30.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants