Metals and Scala 3

(Metals is developed within the Scala Center, but we are both happy and proud to acknowledge it has reached the maturity of a true community developed and maintained project. The Scala Center team is still deeply invested in the project, and as such we will keep the community updated under the “Scala Center Updates” umbrella, because we are dedicated to providing regular and transparent community updates about project plans & progress. Even though all feedback is welcome, Metals collaborators keep the right to make executive decisions. Overview of all Scala Center activities can always be found at https://scala.epfl.ch/records.html and specifically about Metals at https://scalameta.org/metals/)

Dear Scala Contributors,

Recently, with the release of Metals version 0.9.0 we added basic support for Scala 3. Though it already has a number of features implemented, it is still not one the same level as the support for Scala 2. In this article, we will provide some updates on progress on the support for Scala 3 and other improvements planned for the Metals Scala Language Server.

The goal is making Metals work fully with Scala 3 with the same number of features currently available for Scala 2. In order to do that we also need to work on the scalameta parser, which is necessary for a number of features to work properly in Metals and on the Dotty presentation compiler itself. However, in addition to that we will later need to work on scalafmt, which is needed to support formatting in Metals, scalafix, which will provide refactoring options, and mdoc, which is needed for the worksheet support. All of that will both provide features for Metals itself as well as create a proper tooling ecosystem, which will enable developers to migrate to Scala 3.

Planned features for Scala 3:

  1. Show incomplete type names where sensible - in most cases we do not need a full package name and it can make it less readable (for example “Int” instead of “scala.Int”). scalameta/metals-feature-requests#107
  2. Sort completion results to get most relevant completions first. scalameta/metals-feature-requests#110
  3. Exact types for generic methods - for example “map: Int => String” instead of “map : A => B”. scalameta/metals-feature-requests#108
  4. Signature help for type signatures - signature help shows the signature of the currently typed function and doesn’t currently work with type signatures. scalameta/metals-feature-requests#114
  5. Option for standalone compiler for dotty in case of files outside known targets, currently we always use Scala 2.12 for that. scalameta/metals#1653
  6. Auto imports for symbols outside the current scope coming for example from dependencies or different packages. scalameta/metals-feature-requests#113
  7. Advanced completions existing already in Scala 2. scalameta/metals-feature-requests#112
  8. Scalameta parser working with Dotty syntax - parser is used for a number of features and might currently fail on Dotty specific code and cause some smaller issues Roadmap for Metals and Scala 3 scalameta/scalameta#2022
  9. Code formatting - depends on Scalafmt and the scalameta parser. scalameta/metals-feature-requests#122
  10. Worksheets - depends on mdoc and the scalameta parser scalameta/metals-feature-requests#121
  11. Scalafix refactorings - depends on scalafix and the scalameta parser scalameta/metals-feature-requests#123

Milestone 1 (shorterm):

  • shorter names (1. item) - 4-7 days
  • completion sorting (2. item) - 4-7 days
  • scalameta parser without the optional braces (8. item) 1-2 months

Milestone 2:

  • exact types for generic methods (3. item) 1-2 weeks
  • type signatures for signature help (4. item) - 1-2 weeks
  • scalameta optional braces support (8. item) - 1-2 months

Milestone 3:

  • option for standalone compiler for dotty in case of files outside known target (5. item) 1-2 days
  • scalafmt for Scala 3 (9. item) 2-3 months
  • auto imports (6. item) - 2-3 weeks
  • advanced completions (7. item) - 1-2 months

Milestone 4:

  • worksheets alongside mdoc (10. item) 2-3 weeks
  • scalafix for Scala 3 (11. item) 1-2 months

We don’t provide the exact timeline for the later milestones, since it is impossible currently to foresee how much work will be needed on other parts of Metals and there are a number of unknowns we are still facing. We tried to provide an estimate of how much time will each feature take, but they should not be treated literally, but rather as a measure of complexity of each item.

To find the current issues take a look at:

20 Likes

We haven’t updated the thread for a while, but we’ve been hard at work! We had to make some choices along the way to postpone some of the smaller features and focus on more urgent ones. Currently, we have implemented:

  1. Worksheets support starting from Metals v0.9.3, the support for worksheets was needed for numerous educational initiatives and was implemented first within mdoc starting from version 2.2.6
  2. Full scalameta parser support released with scalameta 4.4.0, some Scala 3 features are still changing so minor adjustments will still be needed, but the main AST should be now stable.

We are currently starting to work on scalafmt support and fixing parser bugs along the way.

The rest of the features, some related to the usage of the presentation compiler, will follow up later. Those include:

  • option for standalone compiler for dotty in case of files outside known target
  • exact types for generic methods
  • type signatures for signature help
  • auto imports
  • advanced completions
  • scalafix for Scala 3

Additionally, because mdoc currently only support worksheets for Scala 3, we will also need to migrate the rest of the codebase to fully support typechecked documentation.

20 Likes

Release candidate with support for Scala 3 has just been released! Please do test it out and let us know about any issues!

To make it work you need to use the additional configuration setting:

runner.dialect = scala3

If you have multiple Scala versions inside your project you can use:

fileOverride {
  "glob:**/scala-3*/**" {
    runner.dialect = scala3
  }
}
18 Likes

The final version of Scalafmt with support for Scala 3 has been released!

This also includes :

  • option to configure the indentation
  • rewrite to new syntax
  • automatically add and remove end markers

Full list can be found at at Release v3.0.0 · scalameta/scalafmt · GitHub

The only things left are features in Metals:

  • advanced completions
  • exact types for generic methods

We will follow up with a full blog post with the next plans for Bloop and Metals.

10 Likes

What are “advanced completions”?

NM, found it!