Skip to main content

Metals v0.11.9 - Aluminium

· 18 min read

We're happy to announce the release of Metals v0.11.9, which brings some of the final missing features in Scala 3 and greatly improves its performance. We also had quite a number of contributions in this release and I wanted to thank all the new contributors for their great work!

Commits since last release203
Merged PRs167
Contributors14
Closed issues37
New features21

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

Metals is a language server for Scala that works with VS Code, Vim, Emacs and Sublime Text. 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!

Adjust mismatched type

Until recently it was only possible to add the type to a definition that didn't have it defined. However, it's also quite common for users to change the returned type of the body of a function and in that case any adjustments had to be made manually. Now, whenever the compiler shows type mismatch error Metals should be able to adjust the type for you automatically.

adjust-type

As this feature is quite new and might still require some tinkering, please report any issues you find.

Ammonite completions for Scala 3

Until recently Metals was only offering $file completions for Scala 2, but thanks to zmerr it's also possible to get them in Scala 3.

For more details take a look at the previous announcement

Better Scala CLI support

ScalaCLI is a tool developed by VirtusLab in an effort to create a simple experience of using Scala for all its users. It has a lot of nice features, but one of the main ones is the possibility to use it in scripts. Thanks to alexarchambault, who is also leading the effort on ScalaCLI, Metals now supports ScalaCLI scripts along with the Ammonite ones.

scala-cli

Whenever, Metals will be opened on a file with *.sc extension (but not *.worksheet.sc), users will be prompted to choose which tool they want to use for the script.

Similar to Ammonite, support for it can also be turned on manually with Metals: Start Scala CLI BSP server and stopped with Metals: Stop Scala CLI BSP server. These commands can be used for more fine grained control when to turn on or of scripting support. This is especially useful since ScalaCLI supports will run an additional BSP server running underneath and that can take up some additional resources.

If the script is in a dedicated folder, by default we will treat all the scripts and scala files in that directory as ones that can be used together. So you would be able to import method and classes from those files. However, if the script is contained within a directory that also contains other sources, that script will be treated as a standalone one in order to avoid flaky compilation errors coming from normal files in the workspace.

[Scala 3] Auto import symbols in string interpolation

Previously, the only suggestions for string interpolations were coming from the currently available symbols in scope. This meant that if you wanted to import something from another package, you would need to do it manually.

This problem is now resolved. Users can easily get such symbols automatically imported, which creates a seamless more workflow.

auto-import

These completions will also allow you to automatically import extension methods.

The feature is already available for Scala 2.

[Scala 3] Add autofill named arguments completion

Thanks to great work by jkciesluk Scala 3 completions will also show an autofill all completion item, which will try to fill in all the arguments of the current method using the symbol in scope or with ??? if no symbols match. Users can later tabulate over the different proposal to adjust them.

auto-fill

The feature was already available for Scala 2.

[Scala 3] Improved performance

We've noticed that previous versions of Metals could cause CPU spikes for anyone using Scala 3. To address this, we managed to include a couple performance improvements in this release. This will improve several editor features such as hover, completions, document highlight, and some code actions.

For more details, see the pull requests.

Thanks to tanishiking) for investigation and his great fixes.

Make documentHighlight more reliable

Document highlight allows users to see all occurrences of the symbol currently under the cursor in a single file. This was one of the first features developed by me for Metals and previously it would only work in a fully compiled workspace. This means that if users have errors, some of the occurrences might not be highlighted.

Since the feature only works within a single file, this was a perfect candidate for turning into a more interactive feature, which would use the Scala presentation compiler already used in such features as hovers or completions. Thanks to this change document highlight should work even if your code doesn't compile.

document-highlight

This should also make it easier for us to fix any issue that might pop up and it has already improved support for locally defined classes.

[Scala 3] Add completions for case and match

Metals provides additional completions whenever users write match clauses to automatically fill either a single case with one of the possible subtypes or an exhaustive completion with all of them. This was previously not available for Scala 3, but thanks to (jkciesluk) users can now benefit from this feature in their Scala 3 codebases.

exhaustive

The Scala 3 version will additionally work with the Scala enums as well as offer completions for simple cases with one possible type, which might be useful to access values inside it. Moreover, exhaustive completions will also be offered within partial function, for example in a .map{}.

Extract Method code action

Another great feature contributed by jkciesluk is the possibility to extract arbitrary parts of code into a separate function. It will also add any values unavailable in the selected scope as parameters in the new function.

extract-method

The code action will currently not turn any methods or classes into parameters even if they is not available in the scope into which the code is being extracted.

[Scala 2] Add Completions for ivy Imports in Ammonite scripts and worksheets

Both in worksheets and in ammonite scripts you can add dependencies using imports such as:

import $$ivy.`io.circe::circe-core:0.14.2`

which will bring in the circe-core dependency. Starting in this version it will be possible to auto complete group ids, artifact names and their versions.

import-dep

Thanks to LaurenceWarne for the great feature!

We are also working on enabling this feature in Mill, sbt, ScalaCLI and later for Scala 3.

Call hierarchy

This release brings about call hierarchy support, which is an LSP feature that enables users to see which method are invoked in a current method or which methods invoke the current one.

call-hierarchy-dep

This non trivial feature was brought to you by riiswa, thanks for the great work!

A current limitation is that it will only work for methods within the workspace.

[Scala 3] Enable fewer braces for Scala 3 nightly versions

Fewer braces is an experimental Scala 3 feature that enables users to drop braces in more places than the default, for example in function invocations. Previously, Metals would show it as error, but since this version fewer braces option will be recognized by default for the Scala 3 nightly versions.

Read more about fewer braces here.

More work is required to enable auto formatting with this option and will be worked on in the near future.

Various

This release also features a number of smaller fixes and improvements, some of the user facing ones are mentioned here:

  • feature: Include anon classes (val x = new Trait {}) in 'find all implementations' kpodsiad
  • feature: Implement basic Text Explorer support for scalatest kpodsiad and allow running single tests.
  • feature: Better mill-bsp semanticdb support ckipp01
  • feature: Allow extract value code action when using new keyword jkciesluk
  • feature: Provide ConvertToNamedArg code action for constructor invocations jkciesluk)
  • feature: Add Analyze Stacktrace command to metals menu
  • feature: Improved completions in type positions
  • feature: Add completion for extends keyword after classes/traits/objects/enums
  • improvement: Don't show misconfigured test message
  • bugfix: Add backticks where needed in "convert to named arguments" kubukoz
  • bugfix: Try to download semanticdb even if it might not be supported
  • bugfix: Properly write constant types in signatures
  • bugfix: Allow to add jvmopts and env variables when running tests
  • bugfix: Compile project on file deletion PeuTit
  • bugfix: Limit running multiple import build jkciesluk
  • bugfix: Request import build after restart even if notification was dismissed jkciesluk
  • bugfix: Properly cancel all current compilations
  • bugfix: Remove worksheet diagnostics on close
  • bugfix: [Scala 3] Don't throw exception if template ends at end of file
  • bugfix: [Scala 2] Fix argument completions in nested method invocation jkciesluk
  • bugfix: [Scala 2] Fix signature help when named params are present
  • bugfix: Don't show preparing PC message when in fact it was already downloaded
  • bugfix: Properly restart worksheet presentation compiler to show the newest completions from the workspace after the compilation finished
  • bugfix: [Scala 3] Fix implement-all members for anonymous class tanishiking
  • bugfix: Allow to run/debug in ScalaCli when it was started from Metals without .bsp
  • bugfix: Show both companion object and case class when searching of definition for synthetic apply
  • bugfix: [Scala 3] Properly filter symbols if they don't exist in the code anymore jkciesluk
  • bugfix: don't break using-directives by an auto-import for .sc in scala-cli dos65 For a full list take a look at the list of PRs below.
  • bugfix: [Scala 3] - provide a correct defitions for symbols from stdLibPatched package dos65

Contributors

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

$ git shortlog -sn --no-merges v0.11.8..v0.11.9
Tomasz Godzik
Waris Radji
Rikito Taniguchi
Vadim Chelyshov
scalameta-bot
Jakub Ciesluk
Jakub Kozłowski
Kamil Podsiadło
Chris Kipp
Laurence Warne
Titouan
Alexandre Archambault
Anton
Ina Zimmer
dependabot[bot]

Merged PRs

v0.11.9 (2022-10-06)

Full Changelog

Merged pull requests: