[英]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; 我正在使用Play框架与Scala,使用IntelliJ IDEA社区13开发。我已经从终端运行Play; that's all working.
一切正常。 However, IntelliJ isn't recognizing some of the operators used on strings.
但是,IntelliJ无法识别字符串上使用的某些运算符。
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. 它在Play中编译并运行良好。 However, IntelliJ marks the
+
and ->
operators as invalid, giving me a "Cannot resolve symbol +
" when I hover. 但是,IntelliJ将
+
和->
运算符标记为无效,当我悬停时,给我一个“无法解析符号+
” 。
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?
我需要导入或配置什么才能让IntelliJ识别这些运算符?
Evidently, JetBrains have taken a "forever in beta" approach with Scala plugin, so be prepared to see bugs frequently. 显然,JetBrains采用了Scala插件的“永远处于测试阶段”的方法,因此请准备好经常看到错误。 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 .
基本上我想说的是每当你遇到Scala插件的任何问题时,只需将它发布在他们的问题跟踪器上 。
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 . 一旦你确认你有斯卡拉的最新版本和游戏安装和配置的插件,创建一个新的Play应用程序的IntelliJ与所描述的在这里 。
@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. @Randall从另一方面解决问题的方法,让Play生成一个IntelliJ项目,应该可行,但我个人已经发现问题,因为JetBrains对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. Randall在他的评论中给出了答案,你可能没有正确设置你的项目,或者在添加依赖项之后忘记做了
sbt gen-idea
(并重新启动/重新加载Intellij)。 Additionally I've noticed weird Intellij nonrecognition errors often go away after updates to the IDE. 另外我注意到在更新IDE之后,奇怪的Intellij非识别错误经常消失。
I have faced the same problem when I was using mkString
method in scala. 当我在scala中使用
mkString
方法时,我遇到了同样的问题。 And the intellij was throwing compiler alert as 并且intellij正在抛出编译器警报
cannot recognise symbol mkString
无法识别符号mkString
But when I applied toString
method before using the mkString
method. 但是当我在使用
mkString
方法之前应用toString
方法时。 The alert was gone and the code compiled successfully 警报消失了,代码编译成功
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.