7

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"?

mirelon
  • 4,498
  • 6
  • 37
  • 64
  • Intellij's "optimize imports" functionality is buggy. I tend to turn off removal of unused imports in the settings and only use it to add new imports. – lmm Jan 19 '15 at 15:21
  • Possible duplicate of [How to prevent IntelliJ IDEA from deleting unused packages?](http://stackoverflow.com/questions/11154912/how-to-prevent-intellij-idea-from-deleting-unused-packages) – jopasserat Nov 01 '15 at 13:24
  • 1
    Nope. It is not about disabling deleting all imports of unused packages, but about disabling deleting imports which are "used", but IDEA thinks they are "not used". – mirelon Nov 01 '15 at 17:00
  • Do I need to edit the question to get rid of the "duplicate remark" box? – mirelon Nov 01 '15 at 17:01

2 Answers2

14

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".

Dawngerpony
  • 2,660
  • 1
  • 30
  • 25
2

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

zpontikas
  • 5,008
  • 2
  • 33
  • 40
  • 1
    Hmm, nice solution, but there is separate "Java" and "Scala" sections. In "Scala" section the options are the same except "Exclude from Import and Completion" – mirelon Jan 19 '15 at 15:52
  • I thought something from https://confluence.jetbrains.com/display/IntelliJIDEA/Managing+Imports+in+Scala could help, but it doesn't seem so. – mirelon Jan 19 '15 at 15:58