IntelliJ IDEA Report Highlighting error when using routes in Controller
Asked Answered
R

2

35

I have a Scala Play project. I'm using Play 2.2.1. I downloaded Scala, Play 2 supported and SBT plugins. Everything is OK, but When I call route on Action in the Controller appear following error(Look screenshots):

Screenshot1

Screenshot2

I'm using IntelliJ IDEA 12.1.6 Ultimate version. Scala version 2.10.2

Anybody know how to fix this problem?

Thanks in advance!


Edit

When I generate my project to Intellij IDEA via "play idea" command in play console, and I opened project in IDEA project structure was such:

screenshot6

Then I saw answer @millhouse and discussing on this githup([Play 2.2] "play idea" creates not working source mapping in target) and I removed following folders from Sources Folders:

  • target\scala-2.10\src_managed\main\controllers
  • target\scala-2.10\src_managed\main\views

and "Report highlighting error" disappeared, but now there is another error:

screenshot3

and

screenshot7

my route:

screenshot4

And I've changed "Sources Folders" as shown below:

screenshot5

But it doesn't help me. And remains "Unspecified value parametrs" error.

Reddick answered 27/11, 2013 at 6:47 Comment(3)
Upgrade to Intellij IDEA 13 and use File -> Import Project and select SBT project. Generating the idea files with play idea is not necessary anymore.Shedevil
Here's bug report for that: github.com/playframework/playframework/issues/1784Bashaw
This might be related to the following issue: youtrack.jetbrains.com/issue/SCL-7726Assignor
G
50

millhouse's answer helped me find the right answer. Play 2.2 (and perhaps earlier versions, haven't checked) output a scala version of the routes file to project_dir/target/scala-2.10/src_managed/main So for IntelliJ to get the highlighting right you need to make sure that src_managed/main is added as a source folder. The reverse routes for javascript are for some reason included in project_dir/target/scala-2.10/classes_managed so you'll have to add that as well. (In your screenshot it looks like classes_managed is set to excluded so you'll want to un-exclude it by pressing the x button on the right hand side.)

Here's a screen shot of my project structure:

Working Play 2.2 project structure

Update:

In Play 2.3 (or perhaps recent versions of IntelliJ) adding the classes_managed no longer fixes the problem. Instead of adding classes_managed to the project's sources add it to it's dependencies. By doing that IntelliJ should be able to pick up the compiled routes.class.

Working Play 2.3 dependency list

Goatskin answered 5/12, 2013 at 11:18 Comment(6)
If you still get errors doing a File>Invalidate Caches and a restart might help.Goatskin
Brilliant. Worked like a charm!Strigil
I don't have classes_managed folder (play-scala-intro template, Play 2.4.1) :(Vesiculate
I'm still trying to figure out what I have to do to get it working with Play 2.4...Goatskin
@wm_eddie: try re-importing the project from scratch, i.e. delete / rename the .idea subdirectory & re-follow the instructions on: jetbrains.com/help/idea/2016.1/… - resolved the issue in my case. Seems like there may have been some crud left behind when upgrading IDEA / Play.Selaginella
For Play 2.3 you have to mark src_managed/main folder as source to get route package recognized, works for me with IntelliJ 2016.1.1Dispirited
C
8

This is a common problem, it's because IntelliJ needs to be shown where to look for the compiled Scala templates and routes file. Here's how I fixed it on my IntelliJ 12.1 installation:

  • Go to the Module Settings for your project in IntelliJ (select the top-level, hit F4)
  • Choose the Modules item in the Project Structure window that appears
  • Select the projectname item (as opposed to the projectname-build item)
  • Add the compiler's output directory to the Source Folders items;
    • For Scala 2.10 it's target/scala-2.10/classes
    • I personally find the IntelliJ UI for this to be very non-intuitive; you might need to take the target directory and/or one of its subdirectories out of the Excluded Folders first
  • After applying that change, IntelliJ should see the results of compiling each routes and .scala.html file as just-another source file, so they won't show as "broken" and auto-complete should work for them.
Criminology answered 27/11, 2013 at 22:6 Comment(3)
@ Millhouse Why should only add "target/scala-2.10/classes/views" in the sources folder? Why do not you add "target/scala-2.10/classes/controllers" and "target/scala-2.10/classes/models" folder Sources Folder?Reddick
@mr.boyfox You're right, I've updated my answer so that your routes, and .scala.html template files should all get picked up.Criminology
Thanks @millhouse, I tried this but appear another error, please see my editReddick

© 2022 - 2024 — McMap. All rights reserved.