Use sbt as Metals build server
This is a draft documentation of sbt 2.x that is yet to be released. This is a placeholder, copied from sbt 1.x.
Objective
I want to use Metals on VS Code with sbt as the build server.
Steps
To use Metals on VS Code:
- Install Metals from Extensions tab:
- Open a directory containing a
build.sbt
file. - From the menubar, run View > Command Palette... (
Cmd-Shift-P
on macOS) "Metals: Switch build server", and select "sbt"
- Once the import process is complete, open a Scala file to see that code completion works:
Use the following setting to opt-out some of the subprojects from BSP.
bspEnabled := false
When you make changes to the code and save them (Cmd-S
on macOS), Metals will invoke sbt to do
the actual building work.
Interactive debugging on VS Code
- Metals supports interactive debugging by setting break points in the code:
- Interactive debugging can be started by right-clicking on an unit test, and selecting "Debug Test."
When the test hits a break point, you can inspect the values of the variables:
See Debugging page on VS Code documentation for more details on how to navigate an interactive debugging session.
Logging into sbt session
While Metals uses sbt as the build server, we can also log into the same sbt session using a thin client.
- From Terminal section, type in
sbt --client
This lets you log into the sbt session Metals has started. In there you can call testOnly
and other tasks with
the code already compiled.