Repository navigation
Description
Idea
The Working directory field of a DAP run configuration only works with an absolute path. A path like ~/docs/ruby-test is easier to type and to read. In screenshots and when people share their setup, it also doesn't show the user name.
Today
- The field stores its text unchanged (
DebugAdapterServerPanel). - When the debug adapter starts, the text is used as it is (
DebugAdapterDescriptor.createStartServerCommandLine).new File("~/docs/ruby-test").isDirectory()isfalse, because~is not expanded.- Then the working directory is dropped without a message, and the adapter starts in the IDE's directory.
- A run configuration that is stored as project file is already portable: IntelliJ writes the project directory as
$PROJECT_DIR$into.idea/runConfigurations/*.xml. But the dialog always shows the expanded absolute path. So a user can't see that this works, and has no way to enter a path relative to the home directory.
Proposal
- Let the
Working directoryfield (andFile) show a short, readable path, so a user can see that the path follows the project and the field doesn't show the user name. There are three ways to do this, see "Variants" below. - Report a working directory that doesn't exist in
DAPRunConfiguration.checkConfiguration, instead of dropping it without a message. - Optional: a short hint below the field that says which forms are supported, so the feature can be found.
This is a nice to have, not a bug in a common setup: the default working directory is the project directory, and that one works.
Variants
Each variant is described on its own, with its changes, pros and cons.
Variant 1: show ~ in the field, store an absolute path
- The field shows
~/docs/ruby-test, the run configuration stores$PROJECT_DIR$or$USER_HOME$/.... - Changes:
setWorkingDirectory/getWorkingDirectoryandsetFile/getFilein the panel convert between~/...and the absolute path, a browse listener does the same, and~is expanded in the five places that use the values.
A test in IntelliJ IDEA 2024.2 shows that ~ doesn't survive saving:
~/docstyped intoWorking directory, thenApplyandSave All..idea/runConfigurations/Debug_Ruby.xmlthen has<option name="workingDirectory" value="$PROJECT_DIR$/.." />, and the dialog shows/Users/<user>/docswhen it is opened again.~/docs/ruby-test, the project directory, is stored as$PROJECT_DIR$.
So the path is made absolute before it is stored, and IntelliJ then replaces it with a macro. That is good for sharing: $PROJECT_DIR$ and $USER_HOME$ work for every user, ~ only works if the project is at the same place in each home directory.
So this variant changes only what the field shows, and keeps storing an absolute path:
- When the field is filled (
DebugAdapterServerPanel.setWorkingDirectory, same forsetFile): show a path in the home directory as~/.... - When the field is read (
getWorkingDirectory,getFile): expand~again, so the run configuration gets the absolute path, and IntelliJ stores$PROJECT_DIR$or$USER_HOME$as today.
public String getWorkingDirectory() {
return FileUtil.expandUserHome(workingDirectoryField.getText());
}
public void setWorkingDirectory(String workingDirectory) {
this.workingDirectoryField.setText(toHomeRelative(getText(workingDirectory)));
}
/** /Users/me/docs/x -> ~/docs/x; other paths stay as they are. */
private static String toHomeRelative(String path) {
return path.isBlank() ? path : FileUtil.getLocationRelativeToUserHome(path, false);
}-
The browse button (
TextBrowseFolderListener) writes the chosen folder as absolute path, and can't open the chooser at a path that starts with~. A small subclass handles both:/** Shows a chosen path in the home directory as ~/..., and opens the chooser at such a path. */ private static final class HomeRelativeBrowseListener extends TextBrowseFolderListener { HomeRelativeBrowseListener(FileChooserDescriptor descriptor, Project project) { super(descriptor, project); } @Override protected String expandPath(String path) { return FileUtil.expandUserHome(super.expandPath(path)); } @Override protected String chosenFileToResultingText(VirtualFile chosenFile) { return FileUtil.getLocationRelativeToUserHome(super.chosenFileToResultingText(chosenFile), false); } }
Used for
workingDirectoryFieldandfileFieldinstead ofTextBrowseFolderListener.
With this, the field shows ~/docs/ruby-test for the default of a new run configuration too (DAPConfigurationFactory sets the project directory), and the stored file keeps $PROJECT_DIR$.
Pros:
- Short and readable, no user name in the field.
- The stored file stays portable, because IntelliJ still writes macros.
- Users who know
~from the shell understand it at once.
Cons:
- The field shows something different from what is stored (
~/...in the field,$PROJECT_DIR$in the file), so the file can't be checked against the dialog. ~only says where a path is in the own home directory; it doesn't say that the path follows the project when it is moved.- IntelliJ's own run configurations don't use
~in their fields, so it is a special case for LSP4IJ. - Conversion code in both directions (panel and browse listener).
Variant 2: show the macros in the field, as IntelliJ's own run configurations do
- The field shows and stores
$PROJECT_DIR$,$PROJECT_DIR$/src,$USER_HOME$/docs. - IntelliJ's run configurations (for example
Application) do this withMacroComboBoxWithBrowseButton: a field with a browse button and a list of macros to insert. At run timeProgramParametersConfigurator.expandPathAndMacrosexpands them. Both exist in IntelliJ IDEA 2024.2 (checked withjavap). - Changes:
- in
DebugAdapterServerPanel, useMacroComboBoxWithBrowseButtoninstead ofTextFieldWithBrowseButtonforWorking directory(and possiblyFile); - in
DAPConfigurationFactory, set$PROJECT_DIR$as default instead of the absolute project path; - in the five places that use the values (table in "Changes for all variants"), expand the macros, for example with
PathMacroManager.getInstance(project).expandPath(value)orProgramParametersConfigurator.
- in
Pros:
- What the field shows is what is stored, so dialog and file match.
- The macros make it visible that the path follows the project; this answers "a user can't see that this works".
- Portable for everybody who checks out the project.
- Same look and behavior as IntelliJ's own run configurations; the list of macros shows what is possible.
- No user name in the field.
Cons:
$PROJECT_DIR$/srcis longer and less familiar thansrcor~/...for users who don't know IntelliJ macros.- The field component changes, so the panel code and its tests change more than in the other variants.
- Existing run configurations that store an absolute path keep showing it until the path is chosen again.
Variant 3: allow relative paths, relative to the project directory
- The field shows and stores
.for the project directory,src, or../other-project. - A test in IntelliJ IDEA 2024.2 shows that a relative path is stored as typed:
.ideain the field gives<option name="workingDirectory" value=".idea" />, and the dialog shows.ideaagain. So the storage needs no change. - Today a relative path doesn't work at run time:
createStartServerCommandLinechecksnew File(".idea").isDirectory()against the directory of the IDE process, not of the project. So the path is dropped without a message.${workspaceFolder}would also get the relative text, and the debug adapter can't resolve it. - Changes:
-
in the five places that use the values (table in "Changes for all variants"), resolve a relative path against the project directory, for example in the getter from "Changes for all variants":
/** The working directory for running: ~ expanded, and a relative path resolved against the project directory. */ public @Nullable String getResolvedWorkingDirectory(@NotNull Project project) { String value = getWorkingDirectory(); if (StringUtils.isBlank(value)) { return value; } Path path = Path.of(FileUtil.expandUserHome(value)); String base = project.getBasePath(); return path.isAbsolute() || base == null ? path.toString() : Path.of(base).resolve(path).normalize().toString(); }
-
the browse button writes a chosen folder inside the project as relative path (
FileUtil.getRelativePath(projectDir, chosen)), and opens the chooser at the resolved path; -
DAPConfigurationFactorysets.(or leaves the field empty, if empty means the project directory) instead of the absolute project path.
-
Pros:
- Shortest form:
.orsrc, no user name, nothing to learn. - What the field shows is what is stored.
- Portable: the path follows the project when it is moved or checked out elsewhere, like
$PROJECT_DIR$, which is in fact a relative path written as macro. - Storage needs no change; only the run-time side and the browse button change.
Cons:
- The base must be defined and documented: project directory, not the directory of
.ideaor of a module. In a project with several modules this is not obvious. - A path outside the project, like
../other-projector a folder in the home directory, depends on where the project is checked out; for those an absolute path or$USER_HOME$stays the better choice. - IntelliJ's own run configurations use macros, not relative paths, so it is again a special case for LSP4IJ.
- Relative paths that already exist in stored run configurations (if anybody typed one) change their meaning, from the IDE's directory (where they never worked) to the project directory.
Combining variants
- Variants can be combined, for example macros in the field (variant 2) and
~or a relative path accepted when typed (variant 1 or 3).
Changes for all variants
Use: expand the path before it is used
The stored values are read in five places. Each variant needs the expanded path there: ~ expanded (variant 1, and for files edited by hand), macros expanded (variant 2), a relative path resolved against the project directory (variant 3).
| Place | What it does with the value |
|---|---|
DefaultDebugAdapterDescriptor |
working directory of the debug adapter process |
DefaultDebugAdapterDescriptor.getFileType |
file type from the extension of File (works with ~ already, expansion doesn't hurt) |
LaunchUtils.getDapParameters |
${file} and ${workspaceFolder} in the DAP parameters; the debug adapter gets them and doesn't know ~ |
DAPCommandLineState.getFile |
file shown in the title of the starting task |
DebugAdapterManager |
compares File with the path of a file, to reuse a run configuration |
The simplest way: two getters in DAPRunConfigurationOptions that return the expanded value, and the five places call them. The stored getters getWorkingDirectory() and getFile() stay unchanged, because the settings editor uses them to fill the fields.
/** The working directory with a leading ~ expanded, for running; getWorkingDirectory() keeps what the user typed. */
public @Nullable String getResolvedWorkingDirectory() {
String value = getWorkingDirectory();
return value == null ? null : FileUtil.expandUserHome(value);
}
/** The file with a leading ~ expanded, for running; getFile() keeps what the user typed. */
public @Nullable String getResolvedFile() {
String value = getFile();
return value == null ? null : FileUtil.expandUserHome(value);
}Check: say when the directory doesn't exist
In DAPRunConfiguration.checkConfiguration:
String workingDirectory = getOptions().getResolvedWorkingDirectory();
if (StringUtils.isNotBlank(workingDirectory) && !new File(workingDirectory).isDirectory()) {
throw new RuntimeConfigurationWarning("Working directory doesn't exist: " + workingDirectory);
}A warning, not an error: the run configuration can still start, as today, but the dialog and the start show the problem.
Tests
- Variant 1: the field shows a path in the home directory as
~/..., and the run configuration gets the absolute path (stored as$PROJECT_DIR$or$USER_HOME$). - Variant 2: the field shows and stores the macro; the run gets the expanded path.
- Variant 3: a relative path is stored as typed and resolved against the project directory.
getResolvedWorkingDirectory()andgetResolvedFile()expand~and leave other values unchanged.${file}and${workspaceFolder}get the expanded path.checkConfigurationwarns for a directory that doesn't exist.
How this was found
- While taking the screenshots for the Ruby page (
docs/dap/user-defined-dap/ruby-rdbg.md, docs(dap): add the Ruby rdbg screenshots back with real ones #2294) with the test project in~/docs/ruby-test. - The project tree shows
~/docs/ruby-test, theWorking directoryfield shows/Users/<user>/docs/ruby-test. - The stored run configuration has
<option name="workingDirectory" value="$PROJECT_DIR$" />. - Tested in IntelliJ IDEA 2024.2:
~/docsis stored as$PROJECT_DIR$/..,.ideais stored as.idea. - LSP4IJ at
7b66f446.
Pair-programmed with ❤️ by @muescha and ⚙️ by 🤖 Claude Code
Activity
muescha commentedon Nov 26, 2026
I haven't thought yet about how these changes could affect other plugins that build on LSP4IJ's DAP run configuration.
If the change doesn't make sense, I'm fine with closing this issue as won't fix.
fix: a DAP run configuration path that starts with a separator stays …
fix: a DAP run configuration path that starts with a separator stays …