Best way to handle false unused imports in intellij

戏子无情 提交于 2019-12-04 03:13:29

I'm afraid there isn't, I had similar issues especially when using akka and importing the implicit execution context from an ActorSystem in some cases. I recommend defining the value instead of importing. One such example would be:

// Avoid importing the execution context like this
class MyActor extends Actor {
  import context.system.dispatcher
}

// Define it explicitly instead
class MyActor extends Actor {
  implicit val ec = context.system.dispatcher
}

I hope this helps you.

IntelliJ's Scala plugin now allows you to suppress this false warning on a project-wide level. That may not be appropriate for all cases, but it can help. Click the lightbulb then select "Mark import as always used in this project"

Alternatively you can add this directly to your code style xml:

<component name="ProjectCodeStyleConfiguration">
  <code_scheme name="Project" version="173">
    <ScalaCodeStyleSettings>
      <option name="alwaysUsedImports">
        <array>
          <option value="models.slickless.synchronized" />
          <option value="another.import.path" />
        </array>
      </option>
    </ScalaCodeStyleSettings>
  </code_scheme>
</component>

IntelliJ usually stores that file at .idea/codeStyles/Project.xml. It may be a good idea to commit this to your repository so it can be shared.

Unfortunately there isn't a fix and the problem appears to originate in the compiler itself.

See https://youtrack.jetbrains.com/issue/SCL-7335 which leads to https://issues.scala-lang.org/browse/SI-8773 (reported in 2014 but no fix yet).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!