Scala Plugin
Scala Plugin for IntelliJ IDEA and Android Studio
IntelliJ Scala Plugin 2019.2: Functional Code Highlighting, Fine-grained Type Diff, Case Clause Completion, Build Server Protocol, and More
The 2019.2 release of the Scala plugin offers many improvements in different areas. The key focus of this release is a new code highlighting paradigm whereby the highlighting is now cleaner, yet provides even more coding assistance.
1. Functional code highlighting
2. Fine-grained type diff
3. Interactive type hints
4. Wrap / unwrap expressions as you type
5. Unobtrusive redundant code inspections
6. Case clause completion
7. Build Server Protocol
8. Language injection for multiline strings
9. Duplicate code fragment inspection
Functional code highlighting
Previously, IntelliJ IDEA highlighted type mismatch errors with a red squiggly underline. But long underlines are hardly pretty, especially if they span across multiple lines. Outer errors mask inner errors. And if you’re in the process of writing such an expression, it would be constantly underlined solely for being incomplete.
Now we can do better: instead of underlining the whole expression, the Scala plugin now shows a type ascription hint and highlights only the part that doesn’t match the expected type:
This significantly cleans up your editor, while providing even more coding assistance. To learn about the “whys” and the “hows”, see our recent post, Functional Highlighting for Functional Programming. (Note that the mode is controlled by Settings | Languages | Scala | Type mismatch highlighting.)
Fine-grained type diff
Previously, we compared types as indivisible units. While technically this wasn’t wrong, it was hardly convenient, because you had to “parse” and “type-check” the constituent types in your head to understand why exactly the types did not match.
Now we can show a fine-grained, vertically-aligned tooltip for a pairwise comparison:
It’s not just a text-based diff – the algorithm takes syntactic sugar, subtyping, variance, and other tricky stuff into the account.
Interactive type hints
Type annotation hints now support dynamic folding, tooltips, navigation, and brace matching:
What’s more, type hints are shown only when they are truly needed (so, if you previously disabled type hints because they were too noisy, consider giving them another try). That’s the second editor cleanup, alongside with the new type mismatch highlighting.
Wrap / unwrap expressions as you type
Before, you had to invoke the Add braces around single line intention to wrap an expression in curly braces, or the Remove braces intention to unwrap an expression.
Now, IntelliJ IDEA can do that automatically, as you type:
While the intentions are still available (and work just fine), the automatic balancing is much more discoverable and is very handy in practice.
Unobtrusive redundant code inspections
IntelliJ IDEA has always highlighted unused imports or unreachable code as “unused” (as defined by the Color Scheme). Other things, however, were highlighted as “generic warning or error”, which polluted code and concealed actual errors.
Now we highlight all redundant code uniformly, so that the highlighting looks unobtrusive:
That’s the third editor cleanup. Since the highlighting now doesn’t get in your way, we can implement many more useful related inspections. Feel free to vote for the ones you like the most!
Case clause completion
The Scala plugin has already offered exhaustive match completion for quite some time.
Now you can also complete individual case clauses:
What’s more, the completion now works in partial functions, as well as in match
expressions.
Build Server Protocol
The Build Server Protocol (BSP) defines a standard way for build tools to talk to IDEs, allowing you to open projects, run compilation, perform tasks, display error messages, and monitor progress updates directly in the IDE.
For a while, BSP support was an experimental feature, but not anymore – now it’s fully supported:
The supported build tools include Bloop and Fury so far. Support for Mill is coming soon. We’re going to post more details on the BSP integration soon, so stay tuned.
Language injection into multiline strings
Now let’s talk about a few features that are only available in IntelliJ IDEA Ultimate. The first one is the support of language injection into multiline strings:
This feature may come handy for embedding SQL, HTML, or JavaScript into Scala code.
Duplicated code fragment inspection
Did you read the HTML comment in the previous release announcement? If you didn’t, here it is again: “We’ve also implemented duplicates detection, but this capability is not yet enabled in the IntelliJ Platform; expect that feature in the next release”. So, here goes:
Because the feature is implemented as an inspection, you can invoke Run inspection by name | Whole project to fix all the duplicates at once. The algorithm can filter out whitespaces, syntactic sugar, and other accidental details. So, don’t repeat yourself, don’t repeat yourself.
Summary
The new features work in synergy with the implicit hints, which have already cleaned the editor from pervasive “implicit underlines”. The Scala plugin now offers a unique combination of clarity and power: your code looks almost as clean and unclouded as in a plain text editor, while you have intelligence that even the Scala compiler can’t provide, including implicit hints, fine-grained type diffs, inspections, and much more.
Your feedback is very welcome as always. Please report any bugs to YouTrack so that we can fix them as soon as possible. Thank you!
Sincerely,
The IntelliJ Scala plugin team