简体   繁体   中英

Intellij Scala not recognizing operators

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?

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 .

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM