Skip to content

fix: a DAP configuration created from a file starts in the file's directory, and gets its environment - #2271

Merged
lagergren merged 4 commits into
redhat-developer:mainfrom
lagergren:fix/dap-configuration-from-file-working-directory
Nov 25, 2026
Merged

lagergren merged 4 commits into
redhat-developer:mainfrom
lagergren:fix/dap-configuration-from-file-working-directory

Conversation

@lagergren

@lagergren lagergren commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1885, with option 2 from the issue, plus a visible placeholder, as #2233 did for user-defined language servers.

What

A DAP configuration created from a file got the project's directory as its working directory, which the template of the DAP run configuration type stored. So for a file in a subdirectory with its own mise.toml or .envrc, as useEnv/test.js with useEnv/mise.toml in #1660, the directory environment of #1693 didn't apply: its debug adapter ran with the project's tools unless the user set the working directory by hand.

Change

  • The default: the template no longer stores a working directory, so a configuration created from a file has none. Without one, the debug adapter runs in the directory of the configuration's File, or in the File itself when it is a folder, such as a Go package. Without a file, it runs in the project's directory, as before. It gets that directory's environment.
  • ${workspaceFolder}: the working directory if one is set, as before, and otherwise the project's directory, the one the template stored. So launch configurations keep the value they have today: "cwd": "${workspaceFolder}" still names the project's directory for a configuration created from a file.
  • A working directory set in the configuration still wins, for the process and for ${workspaceFolder}. An existing configuration keeps the working directory it stored, and a configuration created from the file of an existing one still copies it.
  • Directories not on disk: a file whose directory isn't on disk, as one in an archive, gives the project's directory. A project's directory which isn't on disk, and the default project, give no working directory, so the process start isn't refused.
  • The placeholder: the empty Working directory field shows "File's directory", or "Project directory" without a file, and follows the File field as it changes. Nothing new is stored.
  • API: new LaunchUtils.getWorkspaceFolder(workingDirectory, project) and LaunchUtils.getWorkingDirectory(workingDirectory, file, project). A descriptor that reads the working directory itself for ${workspaceFolder}, as docs/dap/DeveloperGuide.md showed, gets an empty one for a new configuration; the guide now uses getWorkspaceFolder.
  • Docs: docs/dap/UserGuide.md, docs/dap/DeveloperGuide.md, and the guides of vscode-js-debug, go-delve, swift-lldb and julia. The screenshots of the Configuration tab, of the user guide and of codelldb, go-delve, julia, python-debugpy, swift-lldb and vscode-js-debug, are retaken from the real editor in New UI Dark at 2x: an empty Working directory with its "File's directory" placeholder, a File in the project, and the Installer tab, instead of personal Windows paths. So is the TypeScript launch screenshot of vscode-js-debug (configuration_ts_tab.png), which still showed a very old editor.

Template configurations

DAPConfigurationFactory.createTemplateConfiguration stored the project's directory, and every DAP configuration is cloned from that template: one created from a file, and one added by hand. It now stores none, so both get the empty field and its placeholder, with one rule for where the debug adapter runs. A configuration added by hand without a file still runs in the project's directory. A template that the user edited, and IntelliJ stored, keeps its working directory.

Tests

  • New DAPConfigurationWorkingDirectoryTest (6 tests, heavy project on disk). It creates configurations as the run configuration producer does, from the template and through DebugAdapterManager.prepareConfiguration, with a user-defined debug adapter whose command runs fix: a user-defined language server without a working directory starts in the project's directory, and gets its environment #2233's WorkingDirectoryRecorder, and an environment variable that a test CommandLineEnvCustomizer sets from the working directory. The cases:

    • a file in a subdirectory: the debug adapter runs there, with that directory's environment, and ${workspaceFolder} is the project's directory;
    • no file: the project's directory;
    • a working directory set in the configuration;
    • an existing configuration with a stored working directory, loaded, and copied for its file;
    • a file whose directory isn't on disk, and a folder to debug.

    The environment is checked on 2025.1 and later, the platforms that have directory environments.

  • New DAPSettingsEditorWorkingDirectoryTest (4 tests): the placeholder with and without a file, as the File field changes, and a stored working directory, which is shown and kept.

  • Changed LaunchUtilsPlatformTest (+2 tests): ${workspaceFolder} with and without a working directory; a project's directory which isn't on disk, and the default project.

  • Red-green: without the fix, 6 of the 10 tests of the new classes fail on 2024.2: the debug adapter of a file in sub runs in the project's directory, so does the one of a folder to debug, the template stores the project's directory, and the placeholders are missing. The other 4 pass, as they check what doesn't change. With the fix, all pass.

  • Platforms: the new and changed classes, with dap.configurations.*, dap.descriptors.*, LaunchUtilsTest, DAPDebugProcessInstallerTabTest and DebugAdapterManagerAttachSettingsTest, pass headless on IC 2024.2, IC 2025.3 and IU 2026.3: 62 tests each, 0 failures, 0 skipped.

Behaviour change

Before After
A DAP configuration created from a file stored the project's directory as its working directory, so its debug adapter ran there, with the project's environment It stores none: its debug adapter runs in the file's directory, with that directory's environment. The empty field shows which. ${workspaceFolder} is still the project's directory. A set working directory still wins, and existing configurations keep theirs

A debug adapter command that relied on the project's directory as its working directory, for example through a relative path, now resolves against the file's directory in a new configuration. To run it elsewhere, set the working directory, or use $PROJECT_DIR$ in the command.

…ectory, and gets its environment

A DAP configuration created from a file got the project's directory as its working directory, from the template of the DAP run configuration type. So the directory environment of redhat-developer#1693 (mise, direnv) of a subdirectory didn't apply to a file in it, unless the user set the working directory by hand.

The template no longer sets a working directory. Without one, the Debug Adapter starts in the directory of the configuration's file, and without a file in the project's directory, as before. It gets that directory's environment. A working directory set in the configuration wins, and an existing configuration keeps the one it stored. `${workspaceFolder}` is the working directory if one is set, and otherwise the project's directory, so a launch configuration keeps the value it had. The empty Working directory field shows "File's directory" or "Project directory" as a placeholder; nothing new is stored.

Fixes redhat-developer#1885
…adapter in the directory of its file

The DAP user guide said that a configuration created from a file keeps the project's directory, so that a subdirectory's environment needs its working directory set by hand. It now says where a debug adapter without a working directory runs, what `${workspaceFolder}` is then, and that a configuration created by an earlier version keeps the working directory it stored. The developer guide's descriptor gets its `${workspaceFolder}` from `LaunchUtils.getWorkspaceFolder`, and the guides of the user-defined debug adapters no longer ask for the project's directory as working directory.
…ing directory

The screenshots of the Configuration tab showed a working directory filled in, with personal Windows paths, and most of them had no Installer tab. A configuration now has no working directory unless one is set, and the empty field shows where the debug adapter runs.

Retaken from the real run configuration editor, in New UI Dark at 2x, with each debug adapter created from its bundled template: the general image of the user guide, and the ones of codelldb, go-delve, julia, python-debugpy, swift-lldb and vscode-js-debug. The File is a path in the project, the Working directory is empty with its "File's directory" placeholder, and the launch or attach configuration is the template's. The red boxes mark what the guides point at: the File, or the Attach mode of python-debugpy.
@lagergren lagergren added this to the 0.30.2 milestone Nov 25, 2026
@lagergren lagergren added bug Something isn't working dap Debugging Adapter Protocol labels Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Debug adapters now use a predictable working directory: the configured directory takes precedence; otherwise, they use the selected file’s directory or the project directory when available.
    • ${workspaceFolder} now resolves to the configured working directory or, if unset, the project directory.
  • Documentation

    • Clarified working-directory defaults, fallback behavior, and how the selected directory affects the debug adapter’s environment and command lookup.
    • Updated setup guides to explain when the working-directory field can be left empty.

DAP configurations now select the debug adapter’s process directory from the configured value, file, or project. ${workspaceFolder} resolves separately. The settings UI shows a fallback placeholder, and the guides describe the behavior.

Changes: DAP Working Directory Resolution

Layer / File(s) Summary
Resolve working directory and workspace folder
src/main/java/com/redhat/devtools/lsp4ij/dap/client/LaunchUtils.java, src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPConfigurationFactory.java, src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DefaultDebugAdapterDescriptor.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/LaunchUtilsPlatformTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/DAPConfigurationWorkingDirectoryTest.java, docs/dap/DeveloperGuide.md, docs/dap/UserGuide.md, docs/dap/user-defined-dap/*
Template configurations no longer set a working directory by default. Adapter startup uses the configured directory, or falls back to the file’s on-disk directory and then the project directory when available. ${workspaceFolder} uses the configured directory or the project directory. Tests cover directory selection, DAP parameters, and process environment behavior.
Show the fallback in settings
src/main/java/com/redhat/devtools/lsp4ij/dap/settings/ui/DebugAdapterServerPanel.java, src/main/resources/messages/DAPBundle.properties, src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPSettingsEditorWorkingDirectoryTest.java
The working-directory field displays a file-directory or project-directory placeholder based on the file field. Tests verify placeholder updates and stored values.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: sohamsakhare76-ai, angelozerr

Merge Risk: Minimal · up to 4c204 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main behavior change: a DAP configuration created from a file starts in the file's directory and gets that directory's environment. The changeset matches this (template no longer s…
Description check Passed The description is directly related to the changeset. It references issue #1885, explains the template change, the working-directory fallback order, the new LaunchUtils methods, the placeholder UI cha…
Linked Issues check Passed [#1885] The issue requires that a DAP configuration created from a file use the file's directory as its working directory, so that the directory environment applies. It also requires that ${workspaceF…
Out of Scope Changes check Passed The changes relate to the requirements of #1885:
- LaunchUtils, DAPConfigurationFactory and DefaultDebugAdapterDescriptor implement the working-directory default and the ${workspaceFolder} rule.
- Deb…
Full details: Title check

Explanation

The title names the main behavior change: a DAP configuration created from a file starts in the file's directory and gets that directory's environment. The changeset matches this (template no longer stores a working directory, new LaunchUtils fallback logic, and tests for file-directory start and environment). The title is somewhat long (101 characters) but specific and accurate.

Full details: Description check

Explanation

The description is directly related to the changeset. It references issue #1885, explains the template change, the working-directory fallback order, the new LaunchUtils methods, the placeholder UI change, documentation updates, and the new and changed tests.

Full details: Linked Issues check

Explanation

[#1885] The issue requires that a DAP configuration created from a file use the file's directory as its working directory, so that the directory environment applies. It also requires that ${workspaceFolder} keep resolving to the project directory. The PR addresses both requirements:

  • DAPConfigurationFactory.createTemplateConfiguration no longer sets a working directory, so a configuration created from a file has none.
  • LaunchUtils.getWorkingDirectory(workingDirectory, file, project) returns the configured directory, else the file's directory, else the project directory. DefaultDebugAdapterDescriptor now uses this method to start the debug adapter.
  • LaunchUtils.getWorkspaceFolder(workingDirectory, project) returns the configured directory, else the project directory. This keeps ${workspaceFolder} at the project directory for a configuration created from a file. This is the constraint the issue names.
  • A configured working directory still wins, and existing configurations keep the stored value.
    The PR adds automated tests for these cases: DAPConfigurationWorkingDirectoryTest (6 tests), DAPSettingsEditorWorkingDirectoryTest (4 tests) and LaunchUtilsPlatformTest (+2 tests). The PR reports these tests pass on IC 2024.2, IC 2025.3 and IU 2026.3. The summary used for this assessment does not include the source diff, so the test results are the author's report and were not independently re-run. No unmet coding requirement is found.
Full details: Out of Scope Changes check

Explanation

The changes relate to the requirements of #1885:

  • LaunchUtils, DAPConfigurationFactory and DefaultDebugAdapterDescriptor implement the working-directory default and the ${workspaceFolder} rule.
  • DebugAdapterServerPanel and DAPBundle.properties add an empty-field placeholder. It shows the new default ("File's directory" or "Project directory") and stores no value. This makes the new default visible to users, so it supports the issue's change.
  • The docs (UserGuide, DeveloperGuide and the user-defined DAP guides) document the new default, the ${workspaceFolder} rule and the API change. This is supporting documentation.
  • The screenshot updates are image files excluded from review (ignored_files). They were not inspected. They are documentation only and do not carry code behaviour.
  • The new and changed tests verify the requirements.
    No change was found that is unrelated to #1885. The summary does not show the full diff, so this result covers the changed files listed in the summary.
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: 2d146627-7b8a-4da8-b5f3-e12aba1463a2
Commits

Reviewing files that changed from the base of the PR and between 0a8a114 and 4c204a5.

Files ignored due to path filters: 8

  • docs/dap/images/DAP_config_type_configuration.png is excluded by !**/*.png
  • docs/dap/images/codelldb/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/go-delve/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/julia/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/python-debugpy/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/swift-lldb/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/vscode-js-debug/configuration_tab.png is excluded by !**/*.png
  • docs/dap/images/vscode-js-debug/configuration_ts_tab.png is excluded by !**/*.png
Files selected for processing: 14

  • docs/dap/DeveloperGuide.md
  • docs/dap/UserGuide.md
  • docs/dap/user-defined-dap/go-delve.md
  • docs/dap/user-defined-dap/julia.md
  • docs/dap/user-defined-dap/swift-lldb.md
  • docs/dap/user-defined-dap/vscode-js-debug.md
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/LaunchUtils.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPConfigurationFactory.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DefaultDebugAdapterDescriptor.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/settings/ui/DebugAdapterServerPanel.java
  • src/main/resources/messages/DAPBundle.properties
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/LaunchUtilsPlatformTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPSettingsEditorWorkingDirectoryTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/DAPConfigurationWorkingDirectoryTest.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 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.50000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.11%. Comparing base (0a8a114) to head (4c204a5).

Files with missing lines Patch % Lines
...redhat/devtools/lsp4ij/dap/client/LaunchUtils.java 65.38% 4 Missing and 5 partials ⚠️
...sp4ij/dap/settings/ui/DebugAdapterServerPanel.java 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2271      +/-   ##
==========================================
+ Coverage   55.84%   57.11%   +1.26%     
==========================================
  Files         848      848              
  Lines       36283    36315      +32     
  Branches     5686     7515    +1829     
==========================================
+ Hits        20264    20741     +477     
+ Misses      13101    12593     -508     
- Partials     2918     2981      +63     

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

… the current Configuration tab

The screenshot of the TypeScript launch showed a very old editor: tabs in another order, `Type:` instead of `Debug Mode:`, no `Use the configuration:` choice, a JSON without its `name`, and a working directory filled in with a personal Windows path.

Retaken from the real run configuration editor, in New UI Dark at 2x, as the other Configuration tab screenshots: the VSCode JS Debug server with `Launch TypeScript file` selected and the JSON of its template, the File `/home/user/demo/src/test.ts` in a red box, as the guide asks to update it, and an empty Working directory with its "File's directory" placeholder.
@lagergren
lagergren merged commit 3558129 into redhat-developer:main Nov 25, 2026
10 checks passed
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.

DAP: a configuration created from a file keeps the project's directory as working directory, so a subdirectory's environment doesn't apply

1 participant