Ólafur Páll Geirsson, Gabriele Petronella, Jorge Vicente Cantero
Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals
We are excited to announce the release of Metals v0.5. Metals is a Scala language server that supports code completions, type at point, goto definition, fuzzy symbol search and other advanced code editing and navigation capabilities.
Metals can be used in VS Code, Vim, Emacs, Atom and Sublime Text as well as any other Language Server Protocol compatible editor. Metals works with sbt, Gradle, Maven and Mill thanks to Bloop, a fast Scala build server. Adding support for other build tools is possible through the Build Server Protocol.
Metals is developed at the Scala Center along with contributors from the community.
In this post we are going to demonstrate how to use Metals with VS Code. To get started, install the Scala (Metals) extension on the VS Code Marketplace and open an sbt project directory. The Metals extension will prompt you to import the build.
The build import step can take a while to run and once complete, you can enjoy the features of Metals.
Syntax errors update as you type and type errors are published on file save.
bloop command-line interface
can be installed to test and run programs from a terminal using the same
compilation artifacts as Metals.
Type at point
Hover over an identifier to see its expression type, symbol signature and documentation.
Observe how the active expression is highlighted as the cursor moves.
As you type, code completions are suggested for a range of use-cases such as overriding a method from a superclass or generating an exhaustive pattern match for a sealed type.
Observe that imports are automatically inserted as you complete symbols that are not present in the scope.
When writing arguments for a method call, use parameter hints to see the method signature and available method overloads.
Jump to symbol definitions in your project sources and Scala/Java library dependencies.
Find all usages of a symbol in the workspace, including implicits and
Visit the Metals documentation to learn more about other supported features. The website also includes instructions for how to use Metals with the editors Vim, Emacs, Atom and Sublime Text. However, note that the best supported editor is VS Code.
Collaboration with VirtusLab
As part of a new collaboration between the Scala Center and VirtusLab, VirtusLab will be contributing engineers to work on Metals over the coming months. The VirtusLab engineers Marek Żarnowski (@marek1840) and Tomasz Godzik (@tgodzik) have already contributed several impressive pull requests:
textDocument/foldingRange(#632): code folding that understands Scala syntax.
textDocument/documentHighlight(#621): highlight occurrences of a symbol in the current file.
textDocument/completion(#640): override def completions without the need to type "override def ".
It is our pleasure to welcome Marek and Tomasz to the team and we look forward to working together with them to improve the Scala code editing experience.
Metals currently does not support several common IDE features:
- Refactorings such as rename symbol, add missing import, add inferred result type, move class, extract value.
- Running a main function or unit test with attached debugger.
- Triggering code completions, type at point and goto definition in
- Working with hybrid
*.javaprojects, although you can try using the Eclipse Java Language Server for editing
Metals may not be a good fit if you frequently rely on these features. You might want to try IntelliJ IDEA instead, which has great Scala support and implements all of the features listed above.
Share your feedback
Code completions, type at point and parameter hints are implemented using the Scala presentation compiler, which is maintained by the Scala compiler team at Lightbend.
Metals started as a fork of the dragos-vscode-scala repository in late 2017 and has since then grown into a project with over 40 contributors: Ólafur Páll Geirsson, Gabriele Petronella, Alexey Alekhin, Marek Żarnowski, Iulian Dragos, JesusMtnez, Johan Muedsam, Ben Hutchison, Jonathan Shen, Martin Duhem, PanAeon, Ayoub Benali, Gabriel Volpe, Shane Delmore, Tomasz Godzik, fc, Carlo Sana, Jakub Kozłowski, Eugene Melekhov, Jesús Martínez, Corey O'Connor, Eugene Burmako, Pavel Logvinov, Yashwanth Yadavalli, Arnout Engelen, Carlos Quiroz, Chris, Cody Allen, David Strawn, Edoardo Vacchi, Eric Peters, Evgeniy Tokarev, Joe Ferris, Jozef Koval, Martijn Hoekstra, Michael Pollmeier, Rory Graves, Ross A. Baker, Tim Nieradzik, Alexandre Archambault, keiSunagawa.