Features Scala Scala programming

IntelliJ Scala Plugin 2020.2: Auto-import for Implicits

Implicits are magical. But every wizard knows that any sufficiently complex magic requires a good enough magic wand. In the case of implicits, the Scala plugin can work just as well, or maybe even better. You can already use View | Show Implicit Hints (Ctrl + Alt + Shift + "+") to see beyond appearances:

The Scala plugin can show you how impicits are derived and where they come from (NB: “ambiguous”, not “amphibious”; see more of this in action). So far so good, but suppose that implicits are not yet there:

If you have a pre-2020.2 version of the plugin installed, feel free to copy & paste the following code and try your luck at Scala wizardry:

import scala.concurrent.Future

object ImplicitAutoImport {
  Seq("Now importing implicits").asJavaCollection
  Future("takes only")
  5.seconds
  Seq(Seq(5), Seq(4), Seq(3), Seq(2), Seq(1)).sorted
}

If you managed to solve all the puzzles – congratulations, you are one superhumanly powerful sorcerer! However, by using THIS one weird trick, we humans can do it even faster:

The feature works exactly like the Auto-import for unresolved references in IntelliJ IDEA. The automatic popup makes the feature more discoverable, but it’s also possible to disable the auto-popup and invoke the Import… quick-fix with Alt + Enter:

To try this at home, select Nightly builds as your Settings | Languages | Scala | Updates | Channel (you can revert to a more stable build in the same way at any time):

We’re announcing this feature in advance, before the official release, in order to gather more information and polish off the rough edges. We want your feedback! Please report any bugs to YouTrack. If you have any questions, feel free to ask them in our Gitter.

Sincerely,
The IntelliJ Scala plugin team