Skip to content

fix: expand selection feature not respecting server textDocument/selectionRange response - #1009

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
angelozerr:selectionRange_word_fix
May 1, 2025
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
angelozerr:selectionRange_word_fix

Conversation

@angelozerr

Copy link
Copy Markdown
Contributor

fix: expand selection feature not respecting server textDocument/selectionRange response

Fixes #1007

`textDocument/selectionRange` response

Fixes redhat-developer#1007

Signed-off-by: azerr <[email protected]>
@angelozerr
angelozerr force-pushed the selectionRange_word_fix branch from 3333f26 to f53e93d Compare May 1, 2025 07:18
@angelozerr
angelozerr marked this pull request as ready for review May 1, 2025 07:18
@angelozerr
angelozerr merged commit 0468245 into redhat-developer:main May 1, 2025
lagergren added a commit that referenced this pull request Nov 23, 2026
…Request event (#2122)

## 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](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Cancel), 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 #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).
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.

expand selection feature not respecting server textDocument/selectionRange response

1 participant