Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ keeps removing the import of context.dispatcher from akka tutorial

I am following the akka-in-action tutorial and in chapter 2, there is a class (https://github.com/RayRoestenburg/akka-in-action/blob/master/chapter2/src/main/scala/com/goticks/RestInterface.scala):

trait RestApi extends HttpService with ActorLogging { actor: Actor =>
  import context.dispatcher
  import com.goticks.TicketProtocol._
  ...

The import context.dispatcher is never used, but it is defined with a comment:

  /**
   * Returns the dispatcher (MessageDispatcher) that is used for this Actor.
   * Importing this member will place an implicit ExecutionContext in scope.
   */
  implicit def dispatcher: ExecutionContextExecutor

However, IntelliJ keeps marking the import as "unused" and removing it upon "optimize imports" causing an error value pipeTo is not a member of scala.concurrent.Future[Any].

Is there a way to tell IntelliJ that this import is not intended to be "used", but just to simply provide a context?

Or should the tutorial be updated to not use such "unused import"?

like image 540
mirelon Avatar asked Jan 19 '15 15:01

mirelon


2 Answers

This looks like issue SCL-9326 to me. IntelliJ 15 has a nice fix for this: press alt-enter (on a Mac) and select "mark this import as always used in this project".

like image 195
Dawngerpony Avatar answered Sep 22 '22 17:09

Dawngerpony


Go to settings - editor - general - auto import and add the package to the "Exclude from import and completion" list enter image description here

You can also disable the "Optimize import on the fly" so that it will not remove your imports without your explicit request

like image 23
zpontikas Avatar answered Sep 22 '22 17:09

zpontikas