Skip to content

fix: install Metals with Homebrew's coursier too, and give the cpp_ls, docker-language-server and terraform-ls servers the command of the installed file - #2143

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/metals-coursier-and-template-commands
Nov 23, 2026

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Please merge with "Rebase and merge", not "Squash and merge". Each commit is one change, and its title names what users will notice, so a rebase merge puts both titles in the release notes.

What

A live run of every bundled installer on macOS found two installer bugs. The run used testBundledInstallers, a local, opt-in harness that installs the servers for real into a sandbox; it isn't part of this PR.

  1. The Metals installer works only when Coursier was installed as cs.
  2. A server created from the cpp_ls, docker-language-server or terraform-ls template can't start once the binary is already installed.

Cause

  1. Metals: the check runs which cs, and the run runs cs install metals --install-dir .. Homebrew's coursier formula (brew install coursier, 2.1.27) installs only bin/coursier, a JAR launcher, and no cs; only cs setup and the coursier/formulas tap install cs. With only Homebrew's coursier on the PATH, the live run's log shows:
    - Step: Checking coursier
    > which cs
    - Step: Scala Language Server install problem
    …
    - Step: Install Scala Language Server
    > cs install metals --install-dir .
    [err] … Cannot run program "cs" (in directory ".../.lsp4ij/lsp/metals"): error=2, No such file or directory
    
    The result was a notification that "Installation of Scala Language Server (Metals) failed".
  2. cpp_ls, docker-language-server, terraform-ls: their templates have the command of a server on the PATH (cpp_ls, docker-language-server start --stdio, terraform-ls serve). Their installers download the server into ~/.lsp4ij/lsp/<template>, and their checks are a bare fileExists of that file.
    • So a server created from the template once the file is there passes the check, and keeps the PATH command. That happens for a second server from the template, a server created again, or the same template in another JetBrains IDE, since they share ~/.lsp4ij.
    • The live log of such a new server:
      - Step: Check if cpp_ls is installed
      File exists: …/.lsp4ij/lsp/cpp_ls/cpp_ls
      ${check.file}=$USER_HOME$/.lsp4ij/lsp/cpp_ls/cpp_ls
      …
      [err] The server can't be started: … Cannot run program "cpp_ls": error=2, No such file or directory
      
      Because the check passes, the installer never fixes the command.
    • feat: a passing installer check gives the language server the command of the file it found #2089 gave the other downloaded servers a replaceTemplateCommand, and left these three "on the PATH". But nothing puts them on the PATH, and their check doesn't look there.

Change

  • Metals (c4554ac):
    • The check looks for cs, then for coursier (where … on Windows), before it looks for the launcher.
    • The run installs with cs if it's there, and otherwise with coursier (cmd /C coursier on Windows).
    • The message names both commands and how to get them: cs setup, brew install coursier, or brew install coursier/formulas/coursier. The template's README and docs/user-defined-ls/metals.md say the same.
  • cpp_ls, docker-language-server, terraform-ls (52f6e17): their fileExists checks get an onSuccess replaceTemplateCommand, as clangd and the others already have. It replaces the template's command, by OS as in each template.json, with "${check.file}" plus the arguments that the download gives (none, start --stdio, serve). A command that the user or an earlier download set is kept.

Behaviour changes

Change Commit Who sees it
The Metals installer finds and runs Coursier as coursier too, as Homebrew's coursier formula installs it, not only as cs; without either, its message says how to install Coursier. c4554ac Metals servers created from the template, with Coursier from Homebrew core
A language server created from the cpp_ls, docker-language-server or terraform-ls template once the server is installed gets the command of the installed file, instead of the template's command on the PATH, which couldn't start. 52f6e17 servers created from those three templates when the binary is already in ~/.lsp4ij

Backward compatibility

  • Language servers keep the installer they were created with. Only servers created from the templates after the update get the change.
  • The Metals installer uses only exec, fileExists, showMessage and configureServer, so older LSP4IJ versions run it too, with the coursier fallback.
  • LSP4IJ 0.30.1 and earlier skip replaceTemplateCommand, which they don't know, so their checks of the three templates behave as before.

Test

  • MetalsInstallerTest (new): it runs the bundled Metals installer with an exec that finds only the given commands on the PATH, on macOS and on Windows. It covers the check and the run with only coursier, with only cs, with both, and with neither (the message). 6 of its 7 tests fail without the fix; the 7th, the check with cs, guards what stays.
  • InstallerTaskRegistryFileExistsTest: for each of the three templates, it runs a download from a local asset, then the check for a server with the template's command, which must get the download's command; a changed command is kept. All three tests fail without the fix.
  • BundledTemplateCommandsTest: the three templates are in CHECKS_WHICH_GIVE_THE_COMMAND, checked for each OS and architecture, which fails without the fix. Its rule that a package manager's install ignores the standard error also covers coursier install.
  • Unit test runs: the template and installation tests pass on 2024.2, 2025.3 and IU 2026.3 (185 tests each), and the full suite passes on 2024.2 (2,074 tests, 0 failures, 7 skipped).
  • Live on macOS (Apple Silicon):
    • Metals passes the check, the install, the check with initialize, and the next session's check, with only Homebrew's coursier 2.1.27, with only the native cs 2.1.27, and with both. With neither, the check shows the new message, and the installation isn't counted as done.
    • cpp_ls, docker-language-server and terraform-ls pass every step, and a server created from the template once installed gets the installed file's command and answers initialize.

…ly with cs

The Metals installer found and ran Coursier only as cs: its check ran
`which cs`, and its run `cs install metals --install-dir .`. Homebrew's
coursier formula (brew install coursier) installs only coursier, a JAR
launcher, and no cs, so a user who installed Coursier that way was told that
Coursier is required, and the run, if it ran, failed with
`Cannot run program "cs"`. Only `cs setup` and the coursier/formulas tap
install cs.

The check now looks for cs, and else for coursier (`where` on Windows), before
it looks for the Metals launcher, and the run installs Metals with cs if it is
there, and else with coursier (`cmd /C coursier` on Windows, for
coursier.bat). Both use only the exec, fileExists, showMessage and
configureServer tasks, which every version of LSP4IJ knows. Without either
command, the message names both, and how to install them: `cs setup`,
`brew install coursier`, or `brew install coursier/formulas/coursier`. The
template's README and docs/user-defined-ls/metals.md say the same.

MetalsInstallerTest runs the bundled installer with an exec task that finds only
the given commands on the PATH, on macOS and on Windows.
BundledTemplateCommandsTest also checks that a coursier install ignores its
standard error.
…server or terraform-ls template the command of the file that is already installed

The templates of cpp_ls, docker-language-server and terraform-ls have the
command of a server on the PATH (`cpp_ls`, `docker-language-server start
--stdio`, `terraform-ls serve`), and their installers download the server
into ~/.lsp4ij/lsp/<template> and give it the command of that file. Their
check is a fileExists of that file. So a server created from the template
once the file is there, as a second server from the template, one created
again, or the same template in another JetBrains IDE, which shares ~/.lsp4ij,
passed the check, and kept the command of the template: it couldn't start
(`Cannot run program "cpp_ls": error=2`), and since the check passed, the
installer never gave it the right command.

redhat-developer#2089 gave the checks of the other downloaded servers a replaceTemplateCommand
with the file that they found, and left these three "with their commands on the
PATH". But their installers never put anything on the PATH, and their check
doesn't look there: a server on the PATH isn't found, and the downloaded one
isn't started.

Their checks now replace the command of the template, by OS as in their
template.json, with the file that they found, and the arguments that the
download gives (`serve`, `start --stdio`), as the other checks do. A command
that the user or the download set is kept. An LSP4IJ before 0.30.2 skips the
task, which it doesn't know, and keeps the command as before.

InstallerTaskRegistryFileExistsTest runs the download of each from a local
asset, then the check for a server with the command of the template, and
BundledTemplateCommandsTest lists them among the checks that give the command
of the download, for each OS and architecture.
@lagergren lagergren added this to the 0.30.2 milestone Nov 23, 2026
@lagergren lagergren added bug Something isn't working template-ls install labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • C++ language server, Docker language server, and Terraform language server setup now uses the installed executable when it is detected.
    • Metals setup supports either cs or coursier, including installation through whichever command is available.
  • Documentation
    • Updated setup instructions for C++ language server and Metals, including the supported Coursier commands and installation options.

Installer checks now set server commands from detected C++, Docker, and Terraform LS executables. The Metals installer and setup documentation now support both cs and coursier. Tests cover executable detection and Metals command selection.

Changes: Language server installer setup

Layer / File(s) Summary
Configure commands for installed executables
src/main/resources/templates/lsp/cpp_ls/installer.json, src/main/resources/templates/lsp/docker-language-server/installer.json, src/main/resources/templates/lsp/terraform-ls/installer.json, src/test/java/com/redhat/devtools/lsp4ij/installation/definition/InstallerTaskRegistryFileExistsTest.java, src/test/java/com/redhat/devtools/lsp4ij/launching/templates/BundledTemplateCommandsTest.java, docs/user-defined-ls/cpp_ls.md
The C++, Docker, and Terraform LS installation checks now set server commands from detected executable paths. Tests cover the installer checks and include the three servers in the bundled command checks. The C++ documentation describes when the installed executable becomes the server command.
Support cs and coursier for Metals
src/main/resources/templates/lsp/metals/installer.json, src/test/java/com/redhat/devtools/lsp4ij/installation/definition/MetalsInstallerTest.java, docs/user-defined-ls/metals.md, src/main/resources/templates/lsp/metals/README.md, src/test/java/com/redhat/devtools/lsp4ij/launching/templates/BundledTemplateCommandsTest.java
The Metals installer checks for cs and then coursier, and uses an available command to install Metals. Both successful installation paths configure the server command. Documentation and tests cover both command names and installation instructions.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant MetalsInstaller
  participant cs
  participant coursier
  participant MetalsLauncher
  participant ServerConfiguration
  MetalsInstaller->>cs: Check command availability
  alt cs is available
    MetalsInstaller->>MetalsLauncher: Check for installed launcher
    MetalsInstaller->>cs: Install Metals if needed
  else cs is unavailable
    MetalsInstaller->>coursier: Check command availability
    alt coursier is available
      MetalsInstaller->>MetalsLauncher: Check for installed launcher
      MetalsInstaller->>coursier: Install Metals if needed
    else neither command is available
      MetalsInstaller-->>MetalsInstaller: Display installation guidance
    end
  end
  MetalsInstaller->>ServerConfiguration: Set server command after successful installation
Loading

Suggested reviewers: angelozerr, cppcxy

Merge Risk: Minimal · up to 15041

This change makes the Metals installer work with either cs or coursier, and makes the cpp_ls, Docker and Terraform installer checks set the server command from the downloaded executable. Only servers created from the templates after the update are affected. No concrete merge-blocking risk was identified, and the new tests cover the changed behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: the Metals installer fallback to Homebrew's coursier, and the replaceTemplateCommand fix for the cpp_ls, docker-language-server and terraform-ls templates. Both m…
Description check Passed The description is detailed and matches the changeset. It covers the Metals installer change (cs and coursier fallback), the template command replacement for cpp_ls, docker-language-server and terrafo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: the Metals installer fallback to Homebrew's coursier, and the replaceTemplateCommand fix for the cpp_ls, docker-language-server and terraform-ls templates. Both match the changeset. The title is long (152 characters) and lists several items, but it still states the primary change accurately.

Full details: Description check

Explanation

The description is detailed and matches the changeset. It covers the Metals installer change (cs and coursier fallback), the template command replacement for cpp_ls, docker-language-server and terraform-ls, the behaviour and compatibility impact, and the tests added.

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: c83b3e9d-9b66-44d4-b825-99369e3f4228
Commits

Reviewing files that changed from the base of the PR and between a802177 and 150418a.

Files selected for processing: 10

  • docs/user-defined-ls/cpp_ls.md
  • docs/user-defined-ls/metals.md
  • src/main/resources/templates/lsp/cpp_ls/installer.json
  • src/main/resources/templates/lsp/docker-language-server/installer.json
  • src/main/resources/templates/lsp/metals/README.md
  • src/main/resources/templates/lsp/metals/installer.json
  • src/main/resources/templates/lsp/terraform-ls/installer.json
  • src/test/java/com/redhat/devtools/lsp4ij/installation/definition/InstallerTaskRegistryFileExistsTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/installation/definition/MetalsInstallerTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/launching/templates/BundledTemplateCommandsTest.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 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.22%. Comparing base (a802177) to head (150418a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2143      +/-   ##
==========================================
+ Coverage   53.21%   53.22%   +0.01%     
==========================================
  Files         826      826              
  Lines       34717    34717              
  Branches     5423     7143    +1720     
==========================================
+ Hits        18475    18479       +4     
+ Misses      13472    13466       -6     
- Partials     2770     2772       +2     

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

…hat it runs on

configureServer is LSP4IJ's own task, which gives the command for the OS that the test runs on, so on Windows the run sets "${workingDir}/metals.bat", not the macOS launcher that the test expected.
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working install template-ls

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant