Skip to content

fix: cancel a DAP request with the DAP cancel request, not a $/cancelRequest event - #2122

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/dap-cancel-with-the-cancel-request
Nov 23, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/dap-cancel-with-the-cancel-request

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

What

Cancelling the future of a DAP request sends {"type":"event","seq":N,"event":"$/cancelRequest","body":{"id":<seq>}} to the debug adapter. That isn't DAP: DAP cancels a request with the cancel request, whose requestId is the seq of the request.

Cause

LSP4J 1.0.0's DebugRemoteEndpoint doesn't override RemoteEndpoint.sendCancelNotification. So JsonRpcRequestFuture.cancel sends LSP's $/cancelRequest notification, and DebugMessageTypeAdapter writes it as a DAP event. eclipse-lsp4j/lsp4j#1009 fixes this in LSP4J, but isn't released yet (tracked in #2121).

Change

  • DAPClient.createLauncher builds its launcher with a DebugLauncher.Builder (the new DAPClientLauncher). Its createRemoteEndpoint is LSP4J's, except that it makes a DebugRemoteEndpoint subclass.
  • That endpoint overrides sendCancelNotification:
    • if the adapter's current capabilities have supportsCancelRequest, it sends cancel with requestId set to the request's seq, with LSP4J's CancelArguments;
    • it doesn't wait for the answer, as some adapters, as CodeLLDB, never answer cancel, which would leave a pending entry forever;
    • without the capability, it sends nothing;
    • either way, the future still ends cancelled locally.
  • It also drops the answer to such a cancel, for which RemoteEndpoint would log "Unmatched response message".
  • Each session, child sessions included, checks the capabilities of its own adapter.
  • The overrides are marked // TODO LSP4J:, to remove once fix: expand selection feature not respecting server textDocument/selectionRange response #1009 is released. The capability check stays.

Behaviour changes

None today: LSP4IJ never cancels the future of a DAP request. #2107 (progress and cancel) will, and this is the launcher change it plans. Every message other than cancel goes through the same LSP4J code as before.

Test

DAPClientLauncherTest creates the launcher against a debug adapter on a loopback socket, and reads the raw frames on the adapter's end:

  • With supportsCancelRequest, the adapter gets one cancel request with the cancelled request's seq, and then the next request, with no $/cancelRequest event. The adapter answers the cancel, and LSP4J logs no warning.
  • Without it, the adapter gets the next request right after the cancelled one.

On main's launcher, both tests fail: the adapter gets {"type":"event","seq":2,"event":"$/cancelRequest","body":{"id":1}}.

The dap tests pass on 2024.2, 2025.3 and IU 2026.3 (346 each), and the full suite passes on 2024.2 (1861 tests, 0 failures, 7 skipped).

…Request event

LSP4J 1.0.0's DebugRemoteEndpoint inherits RemoteEndpoint.sendCancelNotification, so cancelling the
future of a DAP request sends LSP's $/cancelRequest, which goes out as the DAP event
{"type":"event","event":"$/cancelRequest","body":{"id":<seq>}}. DAP has no such event: a request is
cancelled with the cancel request, whose requestId is the seq of the request.

DAPClient now creates its launcher with a DebugLauncher.Builder whose remote endpoint overrides
sendCancelNotification. When the capabilities of the debug adapter have supportsCancelRequest, it sends
the cancel request without keeping it pending, since some debug adapters (CodeLLDB) never answer it,
and drops the answer when one comes. Otherwise it sends nothing. The future ends cancelled locally
either way.

Nothing in LSP4IJ cancels the future of a DAP request yet; redhat-developer#2107 will. The workaround goes once
eclipse-lsp4j/lsp4j#1009 is released.
@lagergren lagergren added this to the 0.30.2 milestone Nov 22, 2026
@lagergren lagergren added bug Something isn't working dap Debugging Adapter Protocol labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Cancelling a debug request now sends a cancellation message to adapters that support request cancellation.
    • Cancellation responses are handled without disrupting the response flow for the original request.
    • When an adapter does not support cancellation, cancelling a request does not send a cancellation message.

The DAP client now uses a custom launcher. When the adapter advertises cancellation support, the launcher sends a DAP cancel request with the cancelled request’s ID. Tests cover supported and unsupported cancellation.

Changes: DAP request cancellation

Layer / File(s) Summary
Configure cancellation handling
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientLauncher.java
The custom launcher receives client capabilities and sends a DAP cancel request only when supportsCancelRequest is true. It does not track the cancel request as pending, discards unmatched cancel responses, and logs send failures.
Wire and test the custom launcher
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientLauncherTest.java
DAPClient.createLauncher now uses the custom launcher and supplies client capabilities. Loopback adapter tests check the cancel request ID and confirm no cancel request is sent when support is absent.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DAPClient
  participant DAPClientLauncher
  participant RequestFuture
  participant DebugAdapter
  DAPClient->>DAPClientLauncher: create launcher with capabilities
  DAPClientLauncher->>DebugAdapter: send threads request
  RequestFuture->>DAPClientLauncher: cancel request future
  alt supportsCancelRequest is true
    DAPClientLauncher->>DebugAdapter: send cancel with original request ID
    DebugAdapter-->>DAPClientLauncher: respond to cancel request
  else supportsCancelRequest is false
    DAPClientLauncher->>DAPClientLauncher: do not send cancel request
  end
  DebugAdapter-->>DAPClientLauncher: respond to cancelled request
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 55b6e

This change makes cancelled DAP requests use the protocol's own cancel request instead of an LSP-only notification, and only when the adapter advertises support. Nothing in LSP4IJ cancels DAP requests today, so current behavior is unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: DAP cancellation now uses the DAP cancel request instead of an LSP $/cancelRequest event. The raw summary shows DAPClientLauncher sends a DAP cancel request when suppo…
Description check Passed The description explains the problem (LSP4J's DebugRemoteEndpoint sends $/cancelRequest as a DAP event), its cause, the change (a DebugLauncher.Builder with a DebugRemoteEndpoint subclass that sends D…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: DAP cancellation now uses the DAP cancel request instead of an LSP $/cancelRequest event. The raw summary shows DAPClientLauncher sends a DAP cancel request when supportsCancelRequest is true, and the test checks that behavior. The title is 82 characters, which is slightly long but still clear.

Full details: Description check

Explanation

The description explains the problem (LSP4J's DebugRemoteEndpoint sends $/cancelRequest as a DAP event), its cause, the change (a DebugLauncher.Builder with a DebugRemoteEndpoint subclass that sends DAP cancel), the lack of behavior change today, and the test plan. It matches the changeset.

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: 8307f3ef-ddca-4beb-a923-a7ef6e5d485c
Commits

Reviewing files that changed from the base of the PR and between ab2a8ea and 55b6e71.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientLauncher.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientLauncherTest.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 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.56757% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.72%. Comparing base (ab2a8ea) to head (55b6e71).

Files with missing lines Patch % Lines
.../devtools/lsp4ij/dap/client/DAPClientLauncher.java 66.66% 10 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2122      +/-   ##
==========================================
+ Coverage   50.69%   50.72%   +0.02%     
==========================================
  Files         816      817       +1     
  Lines       33910    33946      +36     
  Branches     6979     5295    -1684     
==========================================
+ Hits        17190    17218      +28     
- Misses      14059    14066       +7     
- Partials     2661     2662       +1     

☔ 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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 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 merged commit a12a867 into redhat-developer:main Nov 23, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
…0.1 (#2255)

## What

An audit of the docs against main found wrong information, missing docs
for features merged since 0.30.1, broken links and small mistakes. This
PR fixes the text. The outdated screenshots are retaken in separate PRs.

## Change

### DAP guides
- **DAPSupport.md:**
- The `Cancel` request is supported, with `supportsCancelRequest`
(#2122). It was marked ❌.
  - `Terminate Thread` is also in the Frames view.
  - The Output line links the user guide.
- **DAP user guide:**
- New section, "Console output": ANSI colours, indented groups, hidden
`telemetry` output, and the source link or "Jump to Value Source" after
an output.
- Jump to Source on a lazy variable whose value has no declaration opens
the lazy variable's own declaration.
  - The Frames view also says "the thread has exited".
  - CodeLLDB maps Rust files only.
- **DAP developer guide:**
- The `DAPClient` requests `stepBack`, `reverseContinue`, `locations`,
`setExpression` and `terminateThreads`.
- The rule that a request naming a frame id or a `variablesReference`
goes through `sendInExecutionEpoch`.
  - The `DAP.Threads.Popup` group with `ThreadsPanel.SELECTED_THREADS`.
- Keeping `supportsANSIStyling` when overriding
`createInitializeRequestArguments`.
- **Debug adapter pages:**
- "Log pattern before proceeding", not "processing", in go-delve, julia
and vscode-js-debug.
  - ruby-rdbg: select Attach, since the dialog opens on Launch.
  - codelldb: the C++ TODO is replaced by how to map C/C++ files.

### Developer guides
- **LSPApi.md, fixes:**
- The formatting sample compiles: `isExistingFormatterOverrideable` is
`public`. The javadoc sample of `LSPFormattingFeature` is fixed too.
- The `get*Characters` and `get*Scope` methods return `String` and
`FormattingScope`, not `boolean`.
- The CodeLens sample compares the command's title, not the `Command`,
and has its imports.
- There is one Diagnostic section, with `getTooltip`; the duplicate
section named `getToolTip`, which is never called.
  - The DocumentSymbol table: `getIcon` takes the `boolean`.
- `isEnabled(VirtualFile)` is `false` until a server with an installer
is installed.
- `EditorBehaviorFeature` is named correctly, and the Breadcrumbs
default is given.
  - Two stray `=======` merge markers are gone.
- **LSPApi.md, additions:**
- Sections for the call hierarchy, type hierarchy, on-type formatting
and configuration features.
- The missing methods of CodeAction, CodeLens, Completion, Progress,
DocumentSymbol and References.
- When Find Usages merges a language server's reference with a language
plugin's.
- **DeveloperGuide.md:**
- A custom server API is exposed with `getServerInterface()`, not
`createLanguageClient`.
- The get-server sample had an inverted null check. The Lease sample
checks for a null item, casts to the server API and joins the future.
- The custom `WorkspaceFolderStrategy` sample implements
`getWorkspaceFolders`, so it compiles.
  - All attributes of the `server` extension point are listed.
- `OSProcessStreamConnectionProvider` isn't experimental, starts one
process, and logs to the `Logs` tab.
  - A document matcher that throws counts as no match.
- The missing workspace folders image is replaced by an existing
screenshot.

### User guides
- **UserGuide.md:**
- A Getting started section. The empty LSP console's `Getting Started`
link opens this page.
- The console tree: state badges, the server and instance tooltips, and
`[stdio]` or the socket.
  - Messages that LSP4J can't parse are shown in the traces.
- The warning when IntelliJ 2026.3's own LSP client also serves a file.
- Find Usages lists a declaration once, and lists once a reference that
a language plugin also finds.
- **LSPSupport.md:**
  - Snippet edits of `workspace/applyEdit`.
  - `workspace/executeCommand` traces name the command.
  - When Quick Documentation shows a late hover reply.
  - The completion prefix in a token that spans whitespace.
- `callHierarchy/incomingCalls` and `callHierarchy/outgoingCalls`, not
`textDocument/...`.
  - The `LSP Type Definition(s)` and `LSP Declaration(s)` menus.
  - A reversed link is fixed.
- **README:**
  - "As notification" is the default error reporting.
- "In log" writes a warning to `idea.log` and opens no dialog; the
screenshot of that dialog is removed.
  - LSP4IJ instead of LSP4J.
- The documentation list names the LSP API, the template page and the
DAP pages.

### User-defined language servers and templates
- **UserDefinedLanguageServerTemplate.md:**
- The npm `exec` example matches the bundled TypeScript installer: it
runs in `node_modules`, with a quoted command, and says why (#2084).
- A downloaded file is named after the last segment of the URL's path,
without its query or fragment.
  - The `template.json` example gives JavaScript its `*.js` pattern.
  - The rust-analyzer installer tab is a link, not an inline image.
- **UserDefinedLanguageServer.md:** the template list uses the names
that `Choose template...` shows (Camel, Dart, EO, Stylelint, Vue), and
the Language ID sentence is finished.
- **Server pages:**
  - Ada: the path includes the archive's `integration/` folder.
  - HTML: the template is development-only.
- LemMinX: the installer runs at the first start, not when the server is
created.

## Checks
- **Samples:** the developer-guide samples, and an override of every
method in the new API tables, compile in a throwaway test source. The
samples as they are on main fail with 3 errors.
- **Links:** all relative links and anchors of the changed pages
resolve.
- **Open PRs:** the doc changes of #2229, #2230 and #2233 still apply on
top of this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dap Debugging Adapter Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant