Features Releases Uncategorized

Scala plugin for IntelliJ IDEA 2017.1: Cleaner UI, SBT shell, REPL worksheet, Akka support and more

This update brings many new features and improvements in different areas:

1. User interface

First, we’ve streamlined the project wizard:

Project Wizard

  • IDEA / SBT project formats are now clearly separated.
  • SBT project is now the default format.
  • There’s a brand-new SBT icon!

Next, we’ve simplified the wizard settings (which is especially important for novice users):

Project Settings

The handling of Dotty is upgraded:

Dotty Selection

  • Dotty SDK is now just a subtype of Scala SDK.
  • It’s possible to create / import SBT Dotty projects.

Now you can paste Scala code directly into the Project View, for example you can copy the following text:

object App {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}


…and paste it into the project tree – and the new Scala file with a proper name and a package statement will be created automatically. “Stack Overflow driven development” has never been easier! :)

Paste Class

Last but not least, we’ve reworked all the refactoring / code generation dialogs to make them uniform and easier to use.

2. SBT support

We’ve added a built-in SBT shell, which can be started via the SBT tool window. Autocomplete makes it easier to run SBT commands:

SBT shell

You can also run SBT tasks directly from the SBT tool window:

SBT Tasks

It’s now possible to build projects using SBT (instead of IntelliJ IDEA’s internal build system). As this option is still experimental, it should be manually enabled via Build / Execution / Deployment / Build Tools / SBT / Use SBT shell for build and import:

SBT Preferences

Another experimental option is running tests via SBT:

SBT Tests

Select Use SBT in the Run Configuration to enable the option. Also select Use UI with SBT to present the results in the standard IDEA test runner:

Test Settings

3. Worksheet

Worksheet architecture now supports REPL mode, which evaluates only newly added expressions without recompiling the existing code:

REPL

The Worksheet + REPL combo brings the best of both words: although the evaluation is incremental, you don’t have to wait before typing the next line. Plus you can easily correct previous lines and re-evaluate them, if needed.

As the REPL mode can provide better performance, we plan to use this mode by default in the future. Moreover, we’re considering using the REPL mode for implementation of the standard Scala console.

4. Сode conversion

The Java-to-Scala code conversion is substantially improved. For example, it’s now possible to automatically convert something like this (warning, it contains Java):

Code (before)

…to this:

Code (after)

While previously the conversion worked only for Java code that was copied from IDEA, now it’s possible to convert Java code from text. Here’s an example for you to try:

public class Person {
  private final String firstName;
  private final String lastName;

  public Persion(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
}

Simply paste the snippet into a Scala file to see the result. The plugin relies on IntelliJ IDEA’s parser to detect valid Java code for the conversion.

5. Akka

The Ultimate version of the plugin also got a boost – we’ve improved support for Akka. First, we made Find Usages Akka-aware so now it can classify usages of a message class depending on the context:

Find Usages

You can use this to easily find senders or receivers of a particular message in your code.

Because Akka has many “dynamic” parts, some errors are not reported by the Scala compiler. IDE assistance can be of great help in detecting those errors statically (before they are “detected” at runtime).

For example, IntelliJ IDEA can make sure that arguments to a factory method match the actor constructor:

Props

Another thing that can be automated is the generation of factory methods:

Generate Factory Method

The automatically generated code:

Factory Method

Develop with Pleasure!

Discover more