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:
- 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):
The handling of Dotty is upgraded:
- 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! 🙂
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:
You can also run SBT tasks directly from the SBT tool window:
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:
Another experimental option is running tests via SBT:
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:
3. Worksheet
Worksheet architecture now supports REPL mode, which evaluates only newly added expressions without recompiling the existing code:
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):
…to this:
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:
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:
Another thing that can be automated is the generation of factory methods:
The automatically generated code:
Develop with Pleasure!
James Moore says:
March 23, 2017One of the first things that’s a bit confusing for a new user is the project import dialog box telling me that I need to select the “modules / data to include in the project”. I have no idea what that means (so I just click the OK box, figuring the default is probably right).
https://docs.google.com/document/d/1So4Id-qxn0LFiBNUuzNS-XFgVyxTAHF4K3AT2sEjFLo/pub
Pavel Fatin says:
March 23, 2017Hi James,
Thanks for the report! We completely agree with you – that dialog is confusing and, actually, unnecessary – the Help button might show something like “Press OK here” 🙂 The problem is known, yet we are currently constrained by the architectural limitations. We’ll do our best to circumvent the restrictions and to simplify the project import experience further.
Shane says:
April 17, 2017The ticket you link to as “architectural limitations” is not publicly visible, even when I am logged into youtrack.
Chris Beach says:
March 23, 2017Thanks so much, guys. IntelliJ’s Scala support makes coding an absolute pleasure and I love that improvements keep coming.
If I could have one wish, it would be to see non-compiling Scala files highlighted in the project tree view. At the moment I click through from the “Problems” tab, but it would be really helpful to see more visually which part of the project tree is broken by a code change.
Thanks again and keep up the good work!.
Maxime P says:
March 27, 2017+ 1
Leszek says:
March 23, 2017This is fantastic, thanks for hard work!
We’re closer to times when there will be no need for SBT running in a terminal next to IDEA 🙂
Jacek says:
March 24, 2017Right, Leszek! Can’t wait to see that happened.
p.s. I’d strongly suggest running sbt *inside* a terminal window in IDEA. That way you don’t have to leave your beloved development environment (and have it available under Alt+F12).
p.s.2 Wish there could be a way to launch a new terminal window (to have two or more) using a key shortcut. Currently, have to click the little green plus 🙁
Alexander Podkhalyuzin says:
March 24, 2017You always can map any shortcut on action “Start SBT Shell” in Keymap settings page. But probably you are right that we need to define some default value.
Paweł says:
March 24, 2017Ctrl+Shift+T (a shortcut defined in my system terminal (I’m on ubuntu)) works for me, which is great.
Sven says:
March 24, 2017Great update guys! I love especially the SBT Shell. Unfortunately there is one quirk in conjunction with play projects: The SBT Shell doesn’t react to [Ctrl]+[D] which is required to stop the running play app and return to the SBT console. Any chance to get this solved?
Justin Kaeser says:
March 24, 2017Thanks for noticing. There’s already an issue for this: https://youtrack.jetbrains.com/issue/SCL-11603
Nikolay says:
April 9, 2017Very good news, thanks! )) Glad to see SBT shell inside IDE. Side shell is not so convenient as embedded.
Daniil says:
April 12, 2017is there possible to setup codepage at SBT shell? at Windows 7 cyrillic character representation is broken.
Allan says:
April 16, 2017This is a step in the right direction. Still it is not as easy to use as the original sbt console plugin used to be (when the arrow keys worked to go back to previous commands).
The sbt prompt is displayed in a confusing way: It displays an X when busy and when you type Enter it displays a new prompt on the previous line.
There are no buttons to go to the next or previous error or to control automatic scrolling at the end of the output.
But it is nice to have this feature in Idea.
Hagai says:
June 25, 2017Hi Pavel, since the installation on 17.1 I’m getting “No scala SDK defined on module. Setup a scala SDK…” on each new scala module in my project.
I already defined it several times but it keeps showing up. It’s also defined in the Global Libraries of my project settins.
ideas?
Hagai says:
June 25, 2017Just to mentioned that I upgraded from 16.3 where I didn’t have this issue. I’m using a licensed Ultimate version.
Scala дайджест #7: новая среда AI на основе Scala, популярность языков для DataScience, видео ScalaUA и ScalaDays : IT лента новостей ⋆ iAMX - Развлекательно-инфор says:
July 8, 2017[…] Новая версия plugin-а IDEA с поддержкой Akka […]
Scala дайджест #7: новая среда AI на основе Scala, популярность языков для DataScience, видео ScalaUA и ScalaDays - LIKELY.CLUB says:
July 19, 2017[…] Новая версия plugin-а IDEA с поддержкой Akka […]
Łukasz Lenart says:
October 24, 2018With Shift+CMD+S I can open the sbt-shell window (and hide it) but focus is not set, I cannot type in commands. Hitting Esc puts me back in editor (at least) but still I have to use mouse to set focus in the sbt-shell window. Is it a bug?
Łukasz Lenart says:
October 24, 2018Upgrading to 2018.2.5 resolved the problem 🙂
Guy says:
October 26, 2018Is it possible to load a play configuration file with sbt shell?…
i.e. a command line argument -Dconfig.resource=staging.conf
Rahul says:
January 15, 2019I am new to IntelliJ and Scala. Currently using IntelliJ IDEA 2018.1. I am unable to get the ‘Use REPL mode’ to work. When I have both ‘Use REPL mode’ and ‘Use Interactive mode’ checked, and I type in a line of code, the expression is not evaluated automatically, as one would expect. However, if I uncheck the ‘Use REPL mode’ and leave the ‘Use Interactive Mode’ checked, then the expression is automatically evaluated. That leaves me wondering what then is the difference between the REPL mode and the Interactive mode.
Any help is appreciated.
Thank you.