Skip to content

fix: a user-defined language server without a working directory starts in the project's directory, and gets its environment - #2233

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/user-defined-server-default-working-directory
Nov 25, 2026
Merged

lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/user-defined-server-default-working-directory

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #1886, with option 3 from the issue, plus a visible placeholder.

What

A user-defined language server without a working directory started in the IDE's working directory, which is / on macOS. So the directory environment of #1693 (mise, direnv), shipped in 0.30.0, didn't apply to most user-defined servers, and their commands were looked up in the IDE's PATH.

Change

  • The default: with no working directory (none or blank), a user-defined language server runs in its root, the same directory that ${instanceRoot} names. That's the project's directory, or with serverInstances the root of each instance (feat: several instances of one language server per project #1853). It gets that directory's environment.
  • A configured working directory still wins.
  • Where it applies: stdio, a socket that LSP4IJ starts (feat: reach a language server over a socket (experimental) #1870), and the installer's initialize check. Attach mode starts no process.
  • Instances in archives: an instance whose root is in an archive now runs in the project's directory, as ${instanceRoot} already meant. Before, it had no working directory.
  • Directories not on disk: a project whose directory isn't on disk, and the default project, still give no working directory. Otherwise the platform would refuse to start the process (WorkingDirectoryNotFoundException).
  • The placeholder: the empty Working Directory field shows "Project directory", or "Root of each instance" with serverInstances, in the New Language Server dialog and on the settings page. Nothing new is stored. LanguageServerView.setWorkspaceFolderStrategyConfiguration now goes through the panel, so the placeholder follows a reset of the settings page.
  • Docs: docs/UserDefinedLanguageServer.md and docs/UserDefinedLanguageServerTemplate.md.

Tests

  • New UserDefinedServerWorkingDirectoryTest (8 tests). It runs a recorder process that reports its working directory, and an environment variable that a test CommandLineEnvCustomizer sets from that directory. The cases:

    • stdio and socket;
    • a blank and an explicit working directory;
    • the installer check, with and without a working directory;
    • the default project and a missing project directory.

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

  • Changed tests:

    • UserDefinedServerInstancesTest: 2 assertions now expect the project's directory. The local-root instance tests are unchanged.
    • LanguageServerViewWorkingDirectoryTest: +3 placeholder tests, including the Workspace Folders tab round trip.
    • NewLanguageServerDialogTemplateTest: +1 placeholder test.
  • Red-green: without the fix, 10 of 37 tests fail on 2024.2. The process runs in the IDE's directory, the installer and blank cases get no directory, and the placeholders are empty. With the fix, all pass.

  • Platforms: the new and changed classes pass headless on IC 2024.2, 2025.3 and IU 2026.3: 45 tests each. The server.*, settings.*, launching.* and installation.* packages pass on all three: 503 tests each, 0 failures, with the 4 Windows-only skips as before.

Behaviour change

Before After
A user-defined language server without a working directory started in the IDE's working directory, without a directory environment It starts in the project's directory, or an instance in its root, with that directory's environment. The empty field shows which. A configured working directory still wins

A command that relied on the IDE's working directory, for example through a relative path, now resolves against the project's directory. To run it elsewhere, set the working directory.

…s in the project's directory, and gets its environment

A user-defined language server without a working directory started in the
IDE's working directory, which is rarely meaningful (/ on macOS, the home
or bin directory elsewhere). The environment of a directory (redhat-developer#1693), which
mise or direnv give from a mise.toml or an .envrc, then didn't apply to it,
and its command was looked up in the IDE's PATH.

Without a configured working directory, none or a blank one, a user-defined
language server now runs in its root, which ${instanceRoot} names too: the
project's directory, or with serverInstances the root of each instance, as
since redhat-developer#1853. So it gets the environment of that directory. A configured
working directory still wins. The default applies wherever LSP4IJ starts
the language server: over its standard input and output, over a socket
that LSP4IJ starts it for (redhat-developer#1870), and in the initialize check of an
installer. A language server that LSP4IJ attaches to isn't started, so it
has no working directory. An instance whose root is in an archive now runs
in the project's directory, which ${instanceRoot} already was for it. A
project whose directory isn't on disk, or the default project of an
installer check without a project, gives none, as before, so that the
language server still starts.

The empty Working Directory field of the New Language Server dialog and of
the settings shows the default: "Project directory", or "Root of each
instance" with serverInstances. Nothing new is stored.

Behaviour change: a language server whose command relied on the IDE's
working directory, as with a relative path, now resolves it against the
project's directory. Set the working directory to run it elsewhere.

Fixes redhat-developer#1886
…rectory runs, and what its empty field shows

UserDefinedServerWorkingDirectoryTest starts WorkingDirectoryRecorder, a
JDK-only program that prints the directory it runs in and a variable which
a test CommandLineEnvCustomizer sets to the working directory, as mise or
direnv do. Without a working directory, or with a blank one, the language
server runs in the project's directory and gets its environment, over the
standard input and output and over a socket; a configured working directory
wins; the initialize check of an installer runs where the language server
does; a project whose directory isn't on disk, and the default project,
give none. The environment is checked where the IDE has the extension
point, since 2025.1, and the test fails if a 2025.1+ IDE lacks it, so that
it isn't skipped there.

The light project of the tests has no directory on disk, so the tests
which need it create it, and delete it at their end.

UserDefinedServerInstancesTest: one instance per project and an instance
whose root is in an archive run in the project's directory now; an
instance with a local root still runs in its root.

LanguageServerViewWorkingDirectoryTest and
NewLanguageServerDialogTemplateTest: the empty field shows "Project
directory", and "Root of each instance" with serverInstances, also once the
Server tab is back after the Workspace Folders tab changed the
configuration. The placeholder isn't stored.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Language servers without a configured working directory now default to the project directory, or to each instance’s root when using multiple instances.
    • The settings field indicates which directory will be used by default. A configured working directory takes precedence.
    • Command lookup now follows the selected working directory’s environment, with documented fallback behavior when no working directory is available.
  • Documentation
    • Clarified default working-directory behavior for local projects, multiple instances, and archive-based projects.

When no working directory is configured, a user-defined language server now uses the project directory or, for multiple instances, each instance root when that path exists as a directory. The settings UI displays the applicable default, and documentation and tests describe and verify the behavior.

Changes: Working Directory Defaults

Layer / File(s) Summary
Resolve and verify launch working directories
src/main/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedLanguageServerDefinition.java, src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedServerInstancesTest.java, src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedServerWorkingDirectoryTest.java, src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/WorkingDirectoryRecorder.java, docs/UserDefinedLanguageServer.md, docs/UserDefinedLanguageServerTemplate.md
A configured working directory remains in effect. Otherwise, launch configuration uses the project directory or instance root when it is an existing directory. Tests cover launch and installer startup, and documentation describes directory environment and command lookup behavior.
Display the applicable default in settings
src/main/java/com/redhat/devtools/lsp4ij/settings/LanguageServerView.java, src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java, src/main/resources/messages/LanguageServerBundle.properties, src/test/java/com/redhat/devtools/lsp4ij/launching/ui/NewLanguageServerDialogTemplateTest.java, src/test/java/com/redhat/devtools/lsp4ij/settings/LanguageServerViewWorkingDirectoryTest.java
The empty working-directory field displays the project-directory or per-instance-root label. Workspace-folder configuration updates the displayed label, and tests check the label in the settings view and template dialog.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: d-biehl, angelozerr, muescha

Merge Risk: Minimal · up to bf42e · 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 primary change: a user-defined language server without a working directory now starts in the project directory and receives that directory's environment. It matches the changeset, …
Description check Passed The description is directly related to the changeset. It explains the default working directory change, the placeholder text in the Working Directory field, the archive and non-disk directory handling…
Linked Issues check Passed Issue #1886 asks that a user-defined language server without a working directory receives the environment of the project directory. The PR changes UserDefinedLanguageServerDefinition so that an unset …
Out of Scope Changes check Passed The changes fall into four groups, and each connects to #1886. (1) The default working directory logic in UserDefinedLanguageServerDefinition implements the issue. (2) The tests (UserDefinedServerWork…
Full details: Title check

Explanation

The title names the primary change: a user-defined language server without a working directory now starts in the project directory and receives that directory's environment. It matches the changeset, which changes the default working directory in UserDefinedLanguageServerDefinition and adds placeholders and tests. The title is long (123 characters), but it is still specific and on-topic.

Full details: Description check

Explanation

The description is directly related to the changeset. It explains the default working directory change, the placeholder text in the Working Directory field, the archive and non-disk directory handling, the documentation updates, and the new and changed tests. It references issue #1886 and the behaviour change.

Full details: Linked Issues check

Explanation

Issue #1886 asks that a user-defined language server without a working directory receives the environment of the project directory. The PR changes UserDefinedLanguageServerDefinition so that an unset or blank working directory defaults to the language-server root: the project directory, or the root of each instance with serverInstances. A configured working directory still takes precedence. The default applies to stdio, to sockets that LSP4IJ starts, and to the installer's initialize check. Attach mode starts no process. Projects without an on-disk directory, and the default project, still get no working directory, so the process can start. This is the option the issue names as a possible direction, and the PR description states the compatibility effect (relative commands resolve against the project directory). Automated coverage: UserDefinedServerWorkingDirectoryTest (8 tests) checks the process working directory and a directory-specific environment variable. UserDefinedServerInstancesTest is updated to expect the project directory. The PR reports red-green results on 2024.2 and passing runs on 2024.2, 2025.3, and 2026.3. The environment checks run on 2025.1 and later. The PR description and the summary are the basis for this verdict. I did not re-read the diff hunks.

Full details: Out of Scope Changes check

Explanation

The changes fall into four groups, and each connects to #1886. (1) The default working directory logic in UserDefinedLanguageServerDefinition implements the issue. (2) The tests (UserDefinedServerWorkingDirectoryTest, WorkingDirectoryRecorder, and the changed instance and view tests) verify that behavior. (3) The documentation updates in docs/UserDefinedLanguageServer.md and docs/UserDefinedLanguageServerTemplate.md describe the new default, which changes user-visible behavior. (4) The empty-field placeholder in LanguageServerPanel, LanguageServerView, the message bundle, and the New Language Server dialog shows where the server runs when no working directory is set. This placeholder supports the new default, because users otherwise cannot see the directory that now applies. Nothing new is stored. The LanguageServerView change routes the configuration update through the panel, so the placeholder updates after a settings reset. This is a supporting change for the same behavior. No unrelated functionality was identified 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: 72221302-1900-446a-80f5-aadf6eb20440
Commits

Reviewing files that changed from the base of the PR and between df2fa63 and d55dba7.

Files selected for processing: 11

  • docs/UserDefinedLanguageServer.md
  • docs/UserDefinedLanguageServerTemplate.md
  • src/main/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedLanguageServerDefinition.java
  • src/main/java/com/redhat/devtools/lsp4ij/settings/LanguageServerView.java
  • src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java
  • src/main/resources/messages/LanguageServerBundle.properties
  • src/test/java/com/redhat/devtools/lsp4ij/launching/ui/NewLanguageServerDialogTemplateTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedServerInstancesTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedServerWorkingDirectoryTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/WorkingDirectoryRecorder.java
  • src/test/java/com/redhat/devtools/lsp4ij/settings/LanguageServerViewWorkingDirectoryTest.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 84.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.76%. Comparing base (df2fa63) to head (bf42e59).

Files with missing lines Patch % Lines
...launching/UserDefinedLanguageServerDefinition.java 81.81% 2 Missing ⚠️
...vtools/lsp4ij/settings/ui/LanguageServerPanel.java 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2233      +/-   ##
==========================================
+ Coverage   55.67%   55.76%   +0.08%     
==========================================
  Files         844      844              
  Lines       36091    36108      +17     
  Branches     7464     7468       +4     
==========================================
+ Hits        20094    20134      +40     
+ Misses      13086    13066      -20     
+ Partials     2911     2908       -3     

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

…placeholder

The three screenshots of the New Language Server dialog in
UserDefinedLanguageServer.md showed an empty Working Directory field,
which now shows "Project directory". They are rendered again from the real
dialog, offscreen at 2x in the New UI Dark theme with the Inter font: the
empty dialog with its "Server name must be set" and "Command must be set"
errors, the dialog after choosing the TypeScript template, with its current
command `typescript-language-server --stdio` and its instructions line, and
the socket transport that starts the language server, which connects to
LSP4IJ on an Auto port. Offscreen, the dialog has no window frame or title
bar.
@lagergren
lagergren merged commit e7f4339 into redhat-developer:main Nov 25, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
…d Find Usages screenshots (#2257)

Retakes the screenshots of the New Language Server dialog with the Choose template popup, the current templates and the Project directory placeholder of #2233; the settings page with its header and tabs; the LSP console tree with the tooltips of a language server and of its process; and Find Usages without the repeated declaration (#2219).
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 user-defined LS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A user-defined language server without a working directory doesn't get the environment of the project's directory

1 participant