Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij has wrong scala syntax errors

I have this piece of code:

object Application {
  def main(args: Array[String]) {
    import scala.concurrent.ExecutionContext.Implicits.global

    val ws = new NingWSClient(new AsyncHttpClientConfig.Builder().build())
    ws.url("https://www.google.com").get() onSuccess {
      case resp: WSResponse => {
        println("Hello");
      }
      case _ => {
        println("Error");
      }
    }
  }
}

Every dependency is well defined inside the build.sbt like so:

name := "example"

version := "1.0"

scalaVersion := "2.11.4"

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play-ws" % "2.4.0-M2",
  "com.typesafe.play" %% "play-json" % "2.4.0-M2"
)

But Intellij looks like this when viewing my project:

Intellij

Could somebody tell me what I'm doing wrong because I'm clueless and this is really annoying because my imports are constantly being removed by Intellij.

like image 999
Martijn Avatar asked Dec 14 '14 16:12

Martijn


People also ask

How do I change the Scala version in IntelliJ?

 In most cases your project JDK is not compatible with Scala or sbt version, try to change the Scala Compile Server SDK. Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.

Does IntelliJ work with Scala?

To start working with Scala in IntelliJ IDEA you need to download and enable the Scala plugin. If you run IntelliJ IDEA for the first time, you can install the Scala plugin when IntelliJ IDEA suggests downloading featured plugins. Otherwise, you can use the Settings | Plugins page for the installation.

How do I enable Scala in IntelliJ?

Open IntelliJ IDEA, go to File Menu --> Plugins --> [ Or directly press Ctrl+Alt+S ] Click on "Browse repositories" button and enter "Scala". Select Scala plugin to install it.


1 Answers

This looks like an IntelliJ (or Scala plugin) bug. Sometimes scala namespace does not seem to be handled well - I have seen it with my projects as well since I gave upgraded to version 14. Sometimes it helps to use File / Invalidate Caches/Restart.

Sometimes even adding / removing Scala SDK and invalidating caches does not help. In such case installing scalap.jar from issue SCL-8025 Standard scala library unrecognized on sbt project creation on 2.11.4 might help (the scala plugin location was %userprofile%\.IntelliJIdea14\config\plugins\Scala\lib on my computer).

Another issue SCL-7900 Scala import/auto-complete problem seems to suggest the problem shows when Idea uses JRE from Java 8 - uninstalling 1.8 JDK or setting a IDEA_JDK_64 variable to point to jdk7-64bit files is also supposed to fix the issue.

like image 113
Suma Avatar answered Oct 12 '22 11:10

Suma