How to get Scala imports working in IntelliJ IDEA with the Play framework? - scala

I'm using the Scala plugin for IDEA and normally, it works (almost) perfectly.
However, it seems to have problem with the import statements for the Play framework: I often get the error "Cannot resolve symbol x". Now that doesn't stop the program from working, but it makes autocompletion completely useless.
Example: import org.scalatest.junit._
I already added /opt/play/framework/src and /opt/play/framework/play-1.2.2RC2.jar to classes and sources of my project. (using "Project Structure")
Any ideas on how to solve this? Or is this simply a bug?
(I am using Scala 2.9.0.1, IDEA 10.5 and Scala Plugin 0.4.1084)

Try to add tmp/generated to your sources as well. Eclipse also has this issue, since the Play Framework generate the source files from the templates. See Errors in Eclipse for Scala project generated by Play Framework.

Related

scala autocomplete intellij

I have a strange behavior from intellij and scala. When I try to use auto completion it kind of only works for the suggestions not methods related. Once I type the first names method names it works as shown in the second picture. Any ideas how to fix it ?
I tried:
reset the cache
reload the project
reinstall scala plugin
I'm using intellij Community 2019.2.2
Examples:

Play Framework + Intellij: Super slow compilation times

Is there a way to fix the horrible slow compile times of Play and Scala.
It compiles constantly hudrends of java classes.
Has anyone faced this and solved it?
Thanks
If you run your application with sbt-run, or run as play application in paid version of intellij, instead of running NettyServer or ProdServerStart, then play will use multiple class loaders to only recompile modified files instead of all classes.
I removed completely the enhancer plugin, and the compilation times are now normal.
IMO this is a huge issue of the play framework.
I got the idea from this post, however I did not simply disable the plugin and I did not create any getters and setters. I only commented out the plugin locally. When the app is deployed the plugin is there generating the setters and getters.

Scala not being evaluated on Intellij Scala plugin

Coming from an Eclipse background im trying to learn how to use IntelliJ with Scala.
I've downloaded the plugin and restarted. However when I create a new project, then worksheet the expressions are not being evaluated :
I don't know what the issue is or how to find if Intellij is reporting an issue ? In Eclipse I would check the problems tab. Is there something similar I can check or an alternative method to get this to work ?
After more searching I came across this question : Scala Compiler not found in Intellij IDEA 11 with Play 2.0 project
Using answer by "Chris B" allowed me to create a new project with the Scala library. Hopefully this will be fixed in next release of plugin.
The problem for me was that "Compile library" is always "None", even when I select a library and click "Ok". Interestingly When I select the library the "Apply" button is disabled, maybe its a clue as to whats going on.
Anyway, when I follow the steps in linked question this is now my project facet :
I usually start my IntelliJ worksheet with
object Scribble extends App {
... // Your code goes here
}
This works then with both, worksheet mode and plain Scala mode.
We are planning to publish musch better and faster worksheet version next week. Most probably your issue will be fixed.
Best regards,
Alexander Podkhlayuzin.

Play Framework How to Compile Views for Distribution

I have common views that I want to share across multiple Play Framework 2.2.1 applications. I'm thinking packaging them up into a single library and publishing them to our Maven repo is the way to go, but something isn't working correctly during the compile phase.
My project has a single file My/Namespace/myView.scala.html. After compiling my package jar has a file named exactly as my view. My/Namespace/MyView.scala.html I was expecting to see some class files.
The play framework seems to do something very similar https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/views/helper/twitterBootstrap/twitterBootstrapFieldConstructor.scala.html and looking at their Maven package this seems to compile into a twitterBootstrapFieldConstructor class (along with all the meta classes scala generates):
I'm guessing i'm missing something in my SBT configuration that makes it compile scala.html files...but i'm just not seeing it.
Anyone have some insight into what i should be doing?
It appears the best option at this time is to make use of the Twirl library https://github.com/spray/twirl which is the template engine wrapped up into a similar but distinct API.
sbt .13 support is in a testing phase see https://github.com/spray/twirl/issues/15#issuecomment-32272389 as it appears there's going to be some reconciliation of this project & play's templating libraries (one using the other)

Scala # IntelliJ 12 - Can't fetch docs / some functions are not shown in dropdown. [BUGS]

I've been searching for a long time now to find a decent IDE for Scala.
Eclipse is not satisfying at all, as auto completion doesn't work, somehow. Also, I can't modify the libraries at all in the build path e.g. set the docs/source.
IntelliJ seems better, however, there are some major bugs:
When the drop down menu appears that lists all the function, some of them are sometimes just not shown! I think it's because of scala-library / scala-compiler, it mixes them up or something...
The docs cannot be fetched, I get this message over and over again (here the functions are listed, strange enough...):
This is the library window:
The dependencies and the compiler are set right, I strongly suppose.
Does anyone know what the problem is? And how to fix it? Or is it a known bug?
Is there an IDE that can handle Scala?
Regards!
Typically, searching for names (values/classes/functions/etc.) for auto-complete can be quite slow compared to Java in IntelliJ simply because the automatically imported namespace can be quite large, and it also searches through all implicit conversions. However, I've never seen it refuse to show functions like your screenshot, what version of IntelliJ and Scala plugin are you using?
I've never gotten the pop-up docs to work via attaching JavaDocs (I haven't tried remote fetching), so I'd recommend just ctrl+click to go through to the source to read the documentation there. (However, the function/type definition does popup correctly when sources are attached). I'd suggest posting an issue at http://youtrack.jetbrains.com/issues/SCL if you have the opportunity.
To your final question, the answer is unfortunately no. The tooling for Scala is nowhere near that of Java, but both Scala IDE for Eclipse and IntelliJ are making great progress in changing that, and both are strong in some areas while weak in others. In the end, you'll get limited support either way, so choose whichever fits you best.
I have found the solution to the problem:
The bug was caused by Java Decompiler Plugin. It tried to decompile the binaries of Scala's class-files, which obviously failed. This led to that error message and further led to the Scala plugin not working as it should, thus not displaying some of the functions.
This took me a long time to figure out, I installed 2 other versions of IntelliJ (which apparently imported the JD plugin), NetBeans and downloaded several builds of the Scala Plugin, only to discover this cause. Deactivating Java Decompiler solved it.
Regards.