Skip to main content

Metals v0.10.0 - Tungsten

· 12 min read

We're happy to announce the release of Metals v0.10.0, which is the first release in the "Tungsten" line. In 0.10.x we will focus on polishing existing features, fixing bugs and improving the Scala 3 support at least to the level of Scala 2. This will pave the way towards the 1.0.0 release later this year.

Commits since last release163
Merged PRs79
Contributors14
Closed issues30
New features12

For full details: https://github.com/scalameta/metals/milestone/34?closed=1

Metals is a language server for Scala that works with VS Code, Vim, Emacs, Sublime Text and Eclipse. Metals is developed at the Scala Center and VirtusLab with the help from Lunatech along with contributors from the community.

TL;DR

Check out https://scalameta.org/metals/, and give Metals a try!

  • Support for Scala 2.13.5.
  • Type decorations for definitions.
  • Insert inferred type refactoring.
  • Configuration option for the default Scala version.
  • Code lens to easily discover the copy worksheet command.
  • Improved short names when importing.
  • Debug run/test when using sbt via BSP.
  • [Scala 3] Support for Scala 3.0.0-RC1
  • [Scala 3] Filtering and sorting for completions.
  • [Scala 3] Basic shorter signature support for hover.
  • [Scala 3] Document outline
  • [Scala 3] Code folding
  • [Scala 3] Formatting | in multiline string
  • [Scala 3] Code action to convert to multiline string.
  • [Scala 3] Dependency sources navigation

Type decorations for definitions.

One of the most requested features for Metals was the ability to show the inferred type for anything that does not have it defined explicitly. This includes the type at:

  • value and variable definitions
val a = 1
var b = 2
  • method definitions
def method() = ""
  • variables in pattern matches
list match {
case aa :: tail =>
}
  • lambda parameters
list.map(param => param.toInt)
  • for comprehensions
for(i <- 0 to 10)`

The decoration is based on the information produced during the compilation, so anything new will first need to be compiled to have the type shown.

type-decorations

This feature can easily be controlled by the previously available metals.showInferredType setting and will currently work for clients that allow virtual decoration to be inserted into existing text. Those clients currently include Visual Studio Code, Emacs and Sublime Text (after merging this PR).

Insert inferred type refactoring.

Another highly requested feature and closely related to the type decorations is the ability to automatically insert type annotation. This is achieved using a new Insert type annotations and Insert type annotation into pattern definition refactor code actions. Those actions work in the same places as mentioned in the previous point - method, variables, lambdas etc. - but use the presentation compiler instead of indexes. What it means is that this new feature will work even in some more problematic cases when the file is not yet compiled or in files where type decorations are not yet supported, like in worksheets.

inferred-type

There might be still some work to do when it comes to some more complicated types, but it should work perfectly well for most daily use cases. Please do report any issues you might encounter, as it will help us greatly to polish this new feature.

Configuration option for default Scala version.

Previously, for any standalone files Metals would use the default Scala version 2.12.13. This changed in v0.10.0 and can either be defined with a setting:

"metals.fallbackScalaVersion" : "3.0.0-RC1"

or when the setting is empty or set to automatic Metals will infer the Scala version automatically from the project, which will be the highest Scala version used in the project.

Code lens for copy worksheet command.

In the previous version 0.9.8 a new command was added to Metals that allows clients to export the worksheet output for the users to easily share their results. This however was not easy to discover for a large chunk of the users, which is why the command is also now available by using the code lens at the top of a worksheet file. This will work for any clients that support the copy-worksheet-output command.

Debug run/test when using sbt via BSP.

Thanks to the great work of @adpi2 and @er1c on the scala-debug-adapter Metals now supports debugging when using sbt BSP. The experience should be almost the same as when using Bloop, since the new library reuses the already existing Bloop implementation and will be a standard to use for BSP servers.

To use sbt as a BSP server users still need to use metals.bsp-switch command, which will take care of setting up everything and adding the appropriate plugins.

More information about sbt and BSP can be found in the previously published blogpost.

[Scala 3] Support for Scala 3.0.0-RC1

Scala 3.0.0-RC1 has just been released and it's the first release that starts us on the way towards the full Scala 3 release. Syntax is now stable and the compiler team will now focus on fixing existing issues and polishing the internals.

This is a perfect opportunity to try out Scala 3 alongside Metals and see all the new and interesting features that the language has to offer as well as report any issues.

[Scala 3] Filtering and sorting for completions.

In previous versions of Metals, the completions offered by the language server would just be a list of what is available in the current scope. This however did not provide the best possible experience to the users. Thanks to work by @sellophane those initial results are now filtered and sorted so that the most useful methods and values will be available first.

[Scala 3] Basic shorter signature support for hover.

Together with better completions we also included a better way to display types on hover. Previously, we would always display the full class name with the package prefix, which would mean that some methods could look quite complicated for example:

def method(first: alpha.beta.gamma.DType, second: alpha.beta.gamma.DType)

Thanks to @tanishiking we no longer display the long type for anything that is already imported into scope. So the above method would look like:

def method(first: DType, second: DType)

This needs to be further improved by shortening some of the symbols that are not imported into scope and we still need to apply the same optimization in other places where the type is displayed.

[Scala 3] Parser-based features for Scala 3

Under the hood Metals uses a separate parser implementation that can be found in scalameta and it supports numerous different Scala versions. Thanks to the recent work on supporting Scala 3, we now have a dialect that should parse the Scala 3 syntax correctly on par with 3.0.0-RC1 version.

This parser is used by Metals to provide a number of different features, that should now work correctly for Scala 3:

  • document outline which shows the map for the current source file and can also be searched, which is useful to locate a particular method or value in the current document.
  • folding ranges which enables users to hide parts of their code.
  • automatic management of pipes in multiline string.
  • code action to convert simple string into multiline string.
  • go to definition in Scala 3 dependency sources.

Last mentioned feature together with recently added on-demand semanticdb index generation enables users to properly navigate Scala 3 dependency sources.

A lot of the great work here was done by dos65.

Miscellaneous

  • Fix default version of Scala given to Ammonite.
  • Fix issues when method with implicit symbols would be wrongly renamed.
  • Fix issues with stack trace in debugging not showing the correct path,
  • Fix issue when breakpoints in multiple files would not work together.
  • Ensure Bloop isn't offered as a server in an unsupported workspace.
  • Wait for compilation to finish before starting debug session.
  • Fix references to work properly in standalone files and dependency sources.
  • Fix memory leak in presentation compiler.
  • Fix issues where created files should use back quotes.
  • Rename and references now work for worksheets and sbt files - thanks dos65!
  • Always try to have the shortest path when automatically importing symbols.
  • Fix issues with shadowed symbols being imported incorrectly.
  • Fixed go to definition for Scala 3 sources.

Contributors

Big thanks to everybody who contributed to this release or reported an issue!

$ git shortlog -sn --no-merges v0.9.10..v0.10.0

Tomasz Godzik
Chris Kipp
Vadim Chelyshov
Adrien Piquerez
ag91
Rikito Taniguchi
Arthur McGibbon
Ayoub Benali
Błażej Kardyś
Eric K Richardson
Lorenzo Gabriele
Meriam Lachkar
Pavol Vidlicka
strobe

Merged PRs

v0.10.0 (2021-02-24)

Full Changelog

Merged pull requests: