News Releases Scala Scala programming

IntelliJ Scala Plugin 2021.3 Is Out!

This release brings more improvements to Scala 3 support. There are also several new features to help with day-to-day Scala programming. Let’s take a closer look:

1. Scala 3 support improvements
2. Open cross-compiled projects as Scala 2
3. Data flow analysis for Scala
4. Autocomplete for Scala compiler options
5. Inlay hints for ranges

Scala 3 support improvements

Our main focus in this release has been Scala 3 support:

  • We’ve added highlighting, navigation, and autocompletion for end markers.
  • Autocompletion is now provided for the given, using, and export keywords, soft keywords, and the quiet syntax.
  • The TASTy reader can now parse package objects, as well as variance and bounds in higher-kinded types.
  • The highlighting of lexer and parser errors is now significantly faster.
  • There are more inspections that are compatible with Scala 3.
  • We’ve improved the resolution of given imports and implemented support for final top-level members and abstract lazy vals.

Because Scala 3 support is actively being developed, we recommend using the nightly plugin builds to benefit from the new improvements. To do that, select Nightly builds in Settings | Languages | Scala | Updates | Channel (you can revert to an earlier build in the same place at any time).

While everyone in the IntelliJ Scala team has been focusing on Scala 3, we have attracted interns to implement other features, such as the Data Flow Analysis in this release or the Package Search Integration in the previous one. We’d like to thank them for all the work they’ve done to improve the plugin!

Open cross-compiled projects as Scala 2

Many projects that should be compiled for both Scala 2 and Scala 3 are modeled as Scala 3 projects cross-compiled for Scala 2, even though technically they are Scala 2 projects. (Please don’t confuse cross-compiled projects with mixed Scala 3 / Scala 2 projects, where each module is either Scala 2 or Scala 3, but not both.) Opening such projects as Scala 2 allows the IDE to use the technically correct Scala version and is more reliable:

If you look at the scala3-cross.g8 template, you can see that crossScalaVersions includes both scala2Version and scala3Version, while scalaVersion is set to scala3Version Why does the default Scala version matter? If you only need to build the project, the default Scala version isn’t important. However, if you open the project in an IDE, there are a couple key differences.

Scala 3 libraries store public APIs in .tasty files rather than in .class files. Even if there are no Scala 3 features in those APIs, the IDE has to use Scala 3 algorithms. There are many more IDE features that are necessary for Scala 3 but that are not optimal for Scala 2. It’s wise to use battle-tested and well-optimized implementations when working with Scala 2 code.

If the IDE thinks that a project contains Scala 3, it may actually use Scala 3 features on editing, code generation, and refactoring, even though these features must not be used when compiling the code for Scala 2. Thus, opening a cross-compiled project as Scala 2 is technically more correct. You can configure which version of Scala is used in cross-compiled projects at any time in Settings | Build Tools | sbt.

Data flow analysis for Scala

The Scala plugin now supports data flow analysis, which can help you detect programming errors more easily:

You can read our recent blog post for more details.

Autocomplete for Scala compiler options

There are tons of different options in the Scala compiler, though very few programmers learn them all by heart. Furthermore, those options vary depending on the Scala version in use.

You can now autocomplete the applicable options and see quick documentation for each of them:

Inlay hints for ranges

Have you ever wondered whether 1 to 3 is an inclusive or exclusive range? What about 1 until 3? Or Range(1, 3)? No need to worry – now the answer is clear:

As always, we welcome your feedback. Please report any issues you find to YouTrack. If you have any questions, feel free to ask us on Gitter.

Happy developing!

The IntelliJ Scala Plugin team