Skip to content

fix: a DAP attach without a port is an error that names the field, and the Working directory and File take ~ and relative paths - #2302

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/dap-run-configuration-checks
Nov 27, 2026
Merged

lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/dap-run-configuration-checks

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2293 (Problem 2; Problem 1 was fixed by #2294) and #2299. Two commits, one per issue, for a rebase merge.

What

fix: a DAP attach whose port can't be resolved is an error in the run configuration that names the field (#2293)

In Attach mode, DAPRunConfiguration.checkConfiguration now reports an attach port that LaunchUtils.resolveAttachPort can't resolve, as a RuntimeConfigurationError. The dialog shows it, and IntelliJ shows it before the start, instead of the run failing at connect with java.lang.IllegalArgumentException: port out of range:-1. An attach without a port can never connect, so the error blocks nothing that worked.

  • $port with no number for port: Attach port is missing: set "port" to a port number in the DAP parameters, or enter a port number instead of $port
  • An empty Port: Attach port is missing: enter a port number in the Port field of the Attach tab
  • A Port that isn't a number: Attach port "<text>" is not a number: enter a port number, or $port to take "port" from the DAP parameters

Only an attach with LSP4IJ's own descriptor is checked: a configuration without a server, or with a user-defined server (the templates). The descriptor of a server from an extension point can reach its debug adapter another way (#1798), so it isn't checked, nor is Launch mode or another run configuration class. DAP parameters that aren't valid JSON are left to the run, as before.

feat: the Working directory and File of a DAP run configuration take ~ and relative paths, and a working directory that doesn't exist is a warning (#2299)

The backward-compatible part of #2299: nothing changes in the fields, the settings editor or what is stored. At run time:

  • a leading ~ is the home directory, in both fields;
  • a relative Working directory resolves against the project's directory;
  • a relative File resolves against the working directory when one is set, and otherwise against the project's directory, which is where the debug adapter resolved it before;
  • an absolute path stays exactly as typed.

DAPRunConfigurationOptions gets getResolvedWorkingDirectory(Project) and getResolvedFile(Project) next to the stored getters, and every place that uses the values at run time takes them: the debug adapter's working directory and file type (DefaultDebugAdapterDescriptor), ${file} and ${workspaceFolder} (LaunchUtils.getDapParameters), the title of the starting task (DAPCommandLineState.getFile) and the reuse of a configuration for a file (DebugAdapterManager).

checkConfiguration warns (RuntimeConfigurationWarning; the run still starts, as before) when a working directory is set and, resolved, isn't a directory. The DAP user guide describes the paths and the warning.

The display variants of #2299 (~ or macros in the field) are left out.

Behaviour changes

Case Before After
Attach, Port $port, no port in the DAP parameters The run starts; the console shows port out of range:-1 An error in the run configuration; the run doesn't start
Attach, empty Port, or a Port that isn't a number The same exception at connect An error naming the Port field
Working directory src (relative) Dropped without a message; the adapter runs in the IDE's directory <project>/src
Working directory ~/docs/ruby-test Dropped without a message $HOME/docs/ruby-test
File x.rb with working directory /a/b The adapter got x.rb and resolved it in /a/b /a/b/x.rb, the same file, as an absolute path
File ~/x/a.rb in ${file} The adapter got ~/x/a.rb The absolute path
A working directory that doesn't exist Dropped without a message A warning; the run still starts as before

Tests

  • New: DAPRunConfigurationCheckTest (14: the port check in each case, and the working directory warning), DAPRunConfigurationOptionsResolvedPathTest (6). Added to LaunchUtilsPlatformTest (${file}, ${workspaceFolder}) and DAPConfigurationWorkingDirectoryTest (relative and ~ working directories, reuse of a configuration whose File is relative, to the project or to the working directory).
  • Each failed without its fix and passes with it: the port check 5 of 10, the paths 7 of 28 and then 3 of 21 for the File rule.
  • Headless, 2024.2: all of com.redhat.devtools.lsp4ij.dap.*, 630 tests, and after the File rule the 10 affected classes, 67 tests, with no failure, error or skip.

… configuration that names the field, not "port out of range:-1"

In Attach mode, the client connects to the Port of the Attach tab. When that port can't be resolved, as `$port` when
the DAP parameters have no `port` (the attach configuration of the ruby-rdbg template), LaunchUtils.resolveAttachPort
gives -1, the run starts anyway, and the socket fails with `java.lang.IllegalArgumentException: port out of range:-1`
in the console, which names neither the field nor the fix.

DAPRunConfiguration.checkConfiguration now reports it as a RuntimeConfigurationError, which IntelliJ shows in the run
configuration dialog and before the run, and which keeps the run from starting, since it could never connect:

- `$port` without a number for `port` in the DAP parameters: `Attach port is missing: set "port" to a port number in
  the DAP parameters, or enter a port number instead of $port`
- an empty port: `Attach port is missing: enter a port number in the Port field of the Attach tab`
- a port which isn't a number: `Attach port "<text>" is not a number: ...`

Only an attach that connects to that port is checked: with LSP4IJ's own descriptor, without a server or with a
user-defined server. A Launch, a server from an extension point (whose descriptor can reach its Debug Adapter in another
way for an attach, see DebugAdapterDescriptor.startServer(DebugMode)) and other run configurations are not, and DAP
parameters which aren't JSON are left to the run, as before.

Fixes redhat-developer#2293
…~ and relative paths, and a working directory that doesn't exist is a warning

The `Working directory` and the `File` of a DAP run configuration were used as they were typed. `~/docs/ruby-test` or
`src` isn't a directory to `new File(...)` in the IDE's process, so the working directory was dropped without a word and
the debug adapter started in the IDE's working directory, and `${file}` and `${workspaceFolder}` passed `~` or a relative
path on to the debug adapter, which knows neither.

At run time, in both fields, a leading `~` is now the user's home directory, and an absolute path stays exactly as it
is. A relative `Working directory` is resolved against the project's directory (`project.getBasePath()`). A relative
`File` is resolved against that resolved working directory when one is set, as the debug adapter, which runs there,
resolved it before, and otherwise against the project's directory, where the debug adapter ran without a working
directory. Nothing changes in the fields, in the settings editor or in what is stored: DAPRunConfigurationOptions gets
getResolvedWorkingDirectory(Project) and getResolvedFile(Project) next to the stored getters, and every place that uses
the values at run time takes them:

- DefaultDebugAdapterDescriptor: the working directory of the debug adapter's process, the file whose directory it runs
  in without one, and the file type from the extension of the file
- LaunchUtils.getDapParameters: `${file}` and `${workspaceFolder}` in the DAP parameters
- DAPCommandLineState.getFile: the file in the title of the starting task
- DebugAdapterManager: the File of an existing configuration, compared with the path of a file to reuse that
  configuration, through the new DAPRunConfiguration.getResolvedFile()

DAPRunConfiguration.checkConfiguration warns (RuntimeConfigurationWarning, the run still starts, as before) when a
working directory is set and, resolved, isn't a directory: `Working directory "<path>" is not an existing directory, so
the debug adapter cannot start in it: choose an existing directory, or clear the field`. The DAP user guide says so.

Behaviour change: a relative working directory, which ran in the IDE's own directory before, now resolves against the
project's directory. A relative File gives the same file as before, now as an absolute path: in the working directory,
or without one in the project's directory. Only the options of the generic DAP run configuration
(DAPRunConfigurationOptions) are resolved; the options of other run configurations are used as before.

Fixes redhat-developer#2299
@lagergren lagergren added this to the 0.30.2 milestone Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Run configurations resolve ~, absolute, and relative file and working-directory paths consistently. Relative files use the working directory when set, or the project directory otherwise.
    • ${file} and ${workspaceFolder} use the resolved paths. If a configured working directory is unavailable, the run starts with the IDE’s working directory.
  • Bug Fixes
    • Existing configurations are matched using resolved file paths.
    • Configuration checks flag invalid working directories and report attach-port issues before launch.

DAP run configurations now resolve working-directory and file paths for launch use. Configuration checks report invalid working directories and unresolved attach ports. The user guide describes path resolution and the warning for a nonexistent working directory.

Changes: DAP configuration paths and validation

Layer / File(s) Summary
Resolve configured paths
src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationOptions.java, src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfiguration.java, docs/dap/UserGuide.md, src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationOptionsResolvedPathTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/DAPConfigurationWorkingDirectoryTest.java
Options now resolve working directories and files against the project or home directory. Tests cover relative, absolute, blank, and tilde-prefixed paths. The user guide describes the path rules.
Use resolved paths
src/main/java/com/redhat/devtools/lsp4ij/dap/{DebugAdapterManager.java,client/LaunchUtils.java,configurations/DAPCommandLineState.java,descriptors/DefaultDebugAdapterDescriptor.java}, src/test/java/com/redhat/devtools/lsp4ij/dap/{client/LaunchUtilsPlatformTest.java,descriptors/DAPConfigurationWorkingDirectoryTest.java}
Launch context, command-line file lookup, file type lookup, and existing-configuration matching use resolved paths. Tests cover launch variables, working directories, and configuration reuse.
Validate working directories and attach ports
src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfiguration.java, src/main/resources/messages/DAPBundle.properties, src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationCheckTest.java
Configuration checks warn when a nonblank working directory is not a directory. In applicable attach configurations, unresolved ports produce errors with messages for missing, unresolved, or nonnumeric values. Tests cover these checks and their exceptions.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DAPRunConfigurationOptions
  participant LaunchUtils
  participant DefaultDebugAdapterDescriptor
  DAPRunConfigurationOptions->>LaunchUtils: Provide resolved file and working directory
  DefaultDebugAdapterDescriptor->>LaunchUtils: Pass resolved paths to getWorkingDirectory
Loading
Merge Risk: Minimal · up to 73800

This change resolves ~ and relative paths for DAP run configurations and rejects attach configurations whose port cannot be resolved. The supplied evidence shows no concrete merge-blocking risk. The author reports that the new and affected tests pass.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes in this PR: the attach-port error for DAP run configurations (#2293) and the handling of ~ and relative paths for Working directory and File (#2299). Both match …
Description check Passed The description states the linked issues, explains the port check and the path resolution rules, lists behaviour changes, and describes the tests. It matches the changeset closely.
Linked Issues check Passed [#2293, Problem 2] The objective is to report an unresolvable DAP Attach port before the run starts, with an error that names the field. The reviewed head calls checkAttachPort() from DAPRunConfigurat…
Out of Scope Changes check Passed The PR objectives explicitly include the DAP run-configuration Working directory and File path resolution, the warning for a nonexistent working directory, and the changed call sites that use resolved…
Full details: Title check

Explanation

The title names the two main changes in this PR: the attach-port error for DAP run configurations (#2293) and the handling of ~ and relative paths for Working directory and File (#2299). Both match the changeset, and the title is long but specific.

Full details: Linked Issues check

Explanation

[#2293, Problem 2] The objective is to report an unresolvable DAP Attach port before the run starts, with an error that names the field. The reviewed head calls checkAttachPort() from DAPRunConfiguration.checkConfiguration(). In Attach mode, for a configuration with no server or a UserDefinedDebugAdapterServerDefinition, it calls LaunchUtils.resolveAttachPort(...) and throws RuntimeConfigurationError when the result is -1. The messages distinguish a missing port, an unresolved $ reference, and a nonnumeric value. Invalid JSON parameters are skipped. Extension-point server descriptors and Launch mode are not checked, as the PR states. The reported tests are in DAPRunConfigurationCheckTest. [#2293, Problem 1] The localfs fix is assigned to #2294 in the PR description and PR objectives, so this PR does not need to meet it. The change since the previous reviewed head (09ca58d) affects path handling for leading / or \ paths. It does not change the port check. I did not run the tests; this verdict relies on the reviewed source and the reported results.

Full details: Out of Scope Changes check

Explanation

The PR objectives explicitly include the DAP run-configuration Working directory and File path resolution, the warning for a nonexistent working directory, and the changed call sites that use resolved values (DAPRunConfigurationOptions resolved getters, DAPRunConfiguration check, DefaultDebugAdapterDescriptor, LaunchUtils.getDapParameters, DAPCommandLineState.getFile, DebugAdapterManager). The DAP user guide change documents the same behavior. The tests added (DAPRunConfigurationCheckTest, DAPRunConfigurationOptionsResolvedPathTest, LaunchUtilsPlatformTest, DAPConfigurationWorkingDirectoryTest) cover these changes. No change was found that is unrelated to the stated objectives. Uncertainty: the #2299 issue text was not supplied as a linked issue, so its requirements were checked only through the PR objectives and PR description.

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: 8ce76ec8-5c27-46c8-8dc7-1884dd6318a5
Commits

Reviewing files that changed from the base of the PR and between 09ca58d and 7380084.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationOptions.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationOptionsResolvedPathTest.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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

Thanks @muescha for reporting #2293 and #2299, with the causes traced to the code and the proposals already worked out. That made both fixes straightforward.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.36364% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.55%. Comparing base (a900e49) to head (7380084).

Files with missing lines Patch % Lines
...lsp4ij/dap/configurations/DAPRunConfiguration.java 74.07% 7 Missing ⚠️
...dap/configurations/DAPRunConfigurationOptions.java 81.25% 2 Missing and 1 partial ⚠️
...dap/descriptors/DefaultDebugAdapterDescriptor.java 71.42% 0 Missing and 2 partials ⚠️
...lsp4ij/dap/configurations/DAPCommandLineState.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2302      +/-   ##
==========================================
+ Coverage   58.51%   58.55%   +0.03%     
==========================================
  Files         847      847              
  Lines       36501    36548      +47     
  Branches     7560     7575      +15     
==========================================
+ Hits        21360    21400      +40     
- Misses      12136    12156      +20     
+ Partials     3005     2992      -13     

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

…as it is, also on Windows

On Windows, a path such as /working/directory has no drive, so
FileUtil.isAbsolute says it isn't absolute, and the previous commit
resolved it against the project's directory, to C:\working\directory.
It names a directory from the root of the current drive, and the Debug
Adapter got it as it is before: a path which starts with / or \ now stays
as it is, as an absolute path does. LaunchUtilsPlatformTest failed on
Windows CI with "expected:</working/directory> but was:<C:\working\directory>".

Part of redhat-developer#2299
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 27, 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 27, 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 6c8f7bb into redhat-developer:main Nov 27, 2026
12 checks passed
lagergren added a commit that referenced this pull request Nov 27, 2026
…t changes only documentation, as for a pull request (#2309)

Part of #2298: a push to main that changes only documentation skips the
tests and the plugin verification, as a pull request of documentation
only already does.

## Why

`changes.yml` listed the files of a pull request only, so every push to
main ran the whole test matrix and the verification against every IDE
release, also for documentation only: the code of the commit before,
which its own push had tested. The main push of #2300 (docs only) held
two macOS runners of the organization's short pool in the queue for over
100 minutes, ahead of the pull requests behind it.

## What

- **`changes.yml`:** on a push, the compare API lists the files of the
whole range `before...after`, so that the several commits of a rebase
merge count together. It is documentation only when every file is under
`docs/` or a Markdown file at the root, as for a pull request.
- **Still runs everything:** a push without a previous commit (the first
of a branch), one whose range isn't only new commits (`status` other
than `ahead`, as a rewritten history), and one of 300 files or more,
which the API may cut.
- **Build Plugin zip** still runs on every push: the plugin's
description comes from `README.md`.
- The `changes` jobs of `ci.yml` and `IJ.yml` get `contents: read`, for
the compare API.

## Checked

The step, run locally against main's history:

| Push | Result |
|---|---|
| `10a04d91..a900e49`, #2300 (docs) | documentation only |
| `ff1902e1..10a04d9`, #2289 (code) | runs everything |
| `e25c0382..a900e49`, three merges at once | runs everything |
| `01058929..e25c038`, #2294's rebase merge (docs and a template) |
runs everything |
| `0000…..a900e49`, a new branch | runs everything |
| `4f30741e..a900e49`, a diverged range | runs everything |
| pull requests #2300 / #2302 | documentation only / runs everything, as
before |

actionlint passes on the three workflows, and the branch merges cleanly
with #2308. The push path itself runs only on main, so the first
docs-only push after this merge is its real test.
lagergren added a commit that referenced this pull request Nov 27, 2026
…iJ has told the listeners of the first stop (#2304)

`DAPRefusedResumeSessionTest.testAStopBeforeARefusedResumeAtABreakpointWhichDoesNotSuspendIsWhereTheSessionIsSuspended`
failed once on the IU 2026.3 CI job of #2302, whose changes are
unrelated:

```
The frames where the session paused since it ran to the breakpoint: only at the newer stop expected:<[3]> but was:<[1, 3]>
```

## Cause: a race in the test

IntelliJ marks a session suspended at a stop before it tells the
session's listeners (`sessionPaused`), on the thread that suspended it,
here a pool thread of the DAP client; in between it runs
`logPositionReached` (checked in `XDebugSessionImpl` of 2024.2 and
2026.3). `debug()` returned as soon as the session showed the first
stop, and `recordPauses()` then added its listener, which IntelliJ could
still tell about that first stop:

1. pool thread: `positionReached` for stop 1, the session shows frame 1;
2. test thread: `debug()` sees it, `recordPauses()` adds its listener,
Resume;
3. pool thread: `sessionPaused` for stop 1 reaches the new listener,
recorded as frame 1;
4. then the stops that the test is about, and a pause at frame 3: `[1,
3]`.

The product pauses once per stop and never at the stale stop.

## Fix

The mock DAP server no longer stops by itself at `configurationDone`.
`debug()` waits until the session exists and the server is configured
(and has the breakpoint where there is one), adds a session listener,
sends the first stop, and returns once IntelliJ has told that listener
of the pause. A listener added from then on isn't told of it. All 14
tests start through `debug()`.

## Tests

- **Deterministic reproduction:** a hold on IntelliJ's thread inside
`logPositionReached` at the first stop, after the session shows the stop
and before it tells the listeners. With the old test it fails every time
with the CI message; with this one it passes. The hold isn't kept: it
tests the test's own recording, and depends on an experimental extension
point and a private method's name.
- Headless: `dap.stepping.*` on 2024.2, 28 tests;
`DAPRefusedResumeSessionTest` on IU 2026.3, 14 tests. No failure, error
or skip.

Test only, no change for users.
lagergren added a commit that referenced this pull request Nov 28, 2026
…expandUserHome, which IntelliJ 2025.3 schedules for removal

Since #2302, the Working directory and the File of a DAP run configuration take a leading ~, which
DAPRunConfigurationOptions.resolvePath expanded with FileUtil.expandUserHome. IntelliJ 2025.3 deprecates it and
schedules it for removal, and the plugin verifier reports it against 2025.3 to 2026.3: it is the only API scheduled for
removal that LSP4IJ uses. Its replacement, OSAgnosticPathUtil.expandUserHome, only exists from 2025.3. No other public
API expands ~ on 2024.2 to 2026.3: EelPathUtils.expandUserHome takes an EelDescriptor and doesn't exist in 2024.2, and
the file chooser's NioPathCompletion.expandHome is part of its text field.

DAPRunConfigurationOptions.expandUserHome does what both platform methods do, in 2024.2 and in 2026.3: ~ alone is the
user's home, a ~ before / or \ is replaced with it, and any other path, such as ~user/file, stays as it is. Nothing
changes for the user.

Fixes #2327
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.

Ruby rdbg: the attach configuration of the template has no localfs and no port, so breakpoints aren't hit and attaching fails

1 participant