0
votes

I'm using the Play Framework with Scala, developing using IntelliJ IDEA Community 13. I've got Play running from a terminal; that's all working. However, IntelliJ isn't recognizing some of the operators used on strings.

Here's my code:

package controllers

import play.api.mvc._
import play.api.libs.json._

object Application extends Controller {

  def index = Action {
    Redirect(routes.Application.tasks)
  }

  def tasks = TODO

  def newTask = TODO

  def deleteTask(id: Long) = TODO

  def sayHello = Action(parse.json) { request =>
    (request.body \ "name").asOpt[String].map { name =>
      Ok(Json.toJson(
        Map("status" -> "OK", "message" -> ("Hello " + name)) // this line
      ))
    }.getOrElse {
      BadRequest("Missing parameter [name]")
    }
  }

}

It compiles and runs fine in Play. However, IntelliJ marks the + and -> operators as invalid, giving me a "Cannot resolve symbol +" when I hover.

I know this is more of an inconvenience than anything else, but it's really bothering me. What do I have to import or configure in order to get IntelliJ to recognize those operators?

4
Those don't come from Play, they're stock Scala. Most likely you haven't configured the Scala standard library JARs as a dependency for your project. I recommend using SBT and the gen-idea plug-in to generate a complete IDEA project with all its dependencies properly reflecting those in your build.sbt or build.scala file(s).Randall Schulz

4 Answers

2
votes

Evidently, JetBrains have taken a "forever in beta" approach with Scala plugin, so be prepared to see bugs frequently. I report them on a daily basis, and I gotta admit, that they do solve the issues I post. Basically what I wanna say is whenever you come across any issue with Scala plugin just post it on their issue tracker.

0
votes

Once you confirm you have the latest versions of the Scala and Play plugins installed and configured, create a new Play application with IntelliJ as described here.

@Randall's approach to the problem from the other side, having Play generate an IntelliJ project, should work, but I personally have found issues with that because of a lagging behind due to changes made by JetBrains to IntelliJ. It might still work for you though.

0
votes

Randall gave the answer in his comment, you probabally haven't set up your project correctly, or have forgotten to do sbt gen-idea (and restart/reload Intellij) after adding dependencies. Additionally I've noticed weird Intellij nonrecognition errors often go away after updates to the IDE.

0
votes

I have faced the same problem when I was using mkString method in scala. And the intellij was throwing compiler alert as

cannot recognise symbol mkString

But when I applied toString method before using the mkString method. The alert was gone and the code compiled successfully