IntelliJ style problems after crashing - scala

IntelliJ crashed for me, and in doing so it lost all of my files. They where still in the project folder itself and in git, but within the project window they where gone. I re-installed IntelliJ, and now there are several style issues.
The first is that used code is being marked as unused, and the second is that the colors for the styles are not being displayed either. This is with the new Scala plugin as well (3.0.3). I have already tried clearing the cache to no avail.
EDIT: Throw into the mix IntelliJ isn't compiling either so Im unable to even go to definition anywhere now.

When I see this sort of problem in Intellij, I first try "Refresh all SBT projects." Before I discovered where that was, I used to add a blank to build.sbt and then opt to Refresh at the prompt that popped up. Something similar exists for Maven projects, but I don't have experience with those. In more extreme situations, deleting the project and reimporting use "Import Project" has worked.

Related

IntelliJ SBT project import problems

I'm almost sure that this must have been asked and answered, but I've failed to find an answer in a forest of "almost but not quite" related tissues.
Scenario. I have an SBT project cloned from Git, but it has only source and build.sbt. It builds fine from a command-line sbt, but has no IntelliJ specific project files.
I do "import project", and get to a point where IntelliJ mostly seems to recognize the project. However, several problems remain:
The project has no SDK. This is an easy fix, as the IDE prompts to add one, but I mention it, as it might have relevance to the other problems.
The project (after adding an SDK) will not run. It claims to build properly, but on running, it reports "Error: Could not find or load main class blah.Blah". Now, I intermittently get this on a brand new project, and the solution has always been to pop up the SBT console and build it from there. After that, the problem typically goes away. But...
In this project, there is no option for the SBT console. I can start one from the Terminal, but that's not the one that solves the problem in 2) above. Normally, SBT console is available to me on the bottom line, next to tabs like "Run" "Terminal" "Todo" and the like. But it's not there, and it's not on the View->Tool Windows list (not even greyed out). However, the "SBT" window is offered, but that only handles SBT structure, not actual operations.

IntelliJ source code editor shows false compilation errors

I have a problem with the following odd behaviour of the IntelliJ IDEA development environment (version 14) with scala:
After I reset the (global) scala SDK from a 2.11 version to version 2.10.4 the source code editor shows many compilation errors: list, map, print, (1 to n) etc. are all red.
The SDK is added to global libraries and the jars are all found.
However the code compiles and runs correctly (I rebuilt the project to force recompilation). Has anyone ever experienced something like this?
How can this be fixed?
I am using tha java sdk 1.7.0_55.
In file menu, Invalidate Caches / Restart
also set Incremental Type to SBT in Settings -> Build, Execution, Deployment-> Compiler -> Scala Compiler
There are high chances that you didn't load your project properly, and that's why the errors are appearing. I have written a complete blog post about how you can fix it. And following are the two methods from the write up which can correct your issue.
These two steps should be able to help you, for rest of them please check the link.
1. Importing Project as an SBT Project:
First of all, close your project and import it again after selecting the directory and choose SBT as an External Module. Select Import Project, then go to the project directory, select your project, choose Import Project from external model, opt for SBT and click Next and then Finish. IntelliJ IDEA will ask you to overwrite the .idea file, say Yes to it. After IDEA is done indexing and loading your project, all the issues will be sorted out. The editor will work fine, and you will have your missing features restored.
2. Fixing missing project files with SBT-IDEA:
Sometimes IntelliJ IDEA misses out on the most important project files and shows editor errors along with a broken code completion, however, during the code compilation, everything works as per your expectation. This solution works with a plugin called as SBT-IDEA. Now to enable this plugin, open your terminal and follow the instruction:
a. Create a file plugins.sbt in the directory ~/.sbt/0.13/plugins
b. Now, write the following content to it:
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")
Note: Please check for the latest version at the plugin’s GitHub page.
Save and quit, and execute sudo sbt gen-idea in your project root directory.
I hope it helps!
Thank you.
In my case I changed build.sbt file (added empty line and saved file). Then I Idea re-checked dependencies and indexed. Then everything worked fine.
To remove all the false errors sometimes you need to disable type-aware highlighting
by pressing Ctrl + alt + shift + e for example:
https://blog.jetbrains.com/scala/2011/03/02/type-aware-highlighting/
The errors seem to be caused because Scala plugin re-implements compiler logic and that is imperfect.
More information here in the comments:
https://www.reddit.com/r/scala/comments/5pcwfv/question_what_causes_intellij_idea_highlighter/
This occurs when IntelliJ tries to build your code by itself and fails miserably.
If you know your build is successful, all you need to do is edit the Run Configuration and remove the Build part inside the Before Launch part.
This solution solved it for me!
Try invalidating your caches and restarting IDEA.
(File > Invalidate Cache)
Wait for IDEA to re-index your project (Status indicator on lower right status bar). The caches will sometimes become corrupted. This is most likely to occur upon reorganizing a project as you mentioned you did.

Eclipse: false error with jdk7

I've been having a problem with eclipse that's been stressing me a lot. Whenever I start a new Java porject, everything goes smoothly and perfect, until I "clean" the project (Project -> Clean...) and everything goes to ##~%&...
I keep getting:
XYZ cannot be resolved to a type
Multi-catch parameters are not allowed for source level below 1.7
<> operator is not allowed for source level below 1.7
That's very nice, only that I am importing all required classes and I do have 1.7 since the begginig. It's the only version I've installed. I've already tried this and other similar responses for the last few days with no avail.
A solution was to create a new project, copy and paste all packages/clases, which worked for a while, but I added UMLet to the project and again... Removing UMLet plugin did nothing for me.
BTW, even with the "errors", my project runs without any problem, therefore I know they're not real. I could keep working, but then, I can't see when a real error arises...
Does anyone got a final solution to get rid of this false errors?
EDIT:
I forgot to mention that I'm working with Kepler.
EDIT 2:
Here are screen captures with the requested information.
You can solve this by setting up correct JRE environment in Eclipse as below.
Go to Project => Properties => Java Build Path
Click on Libraries
Select JRE System Library
Click on Edit button at right hand side
Set Execution Environment to Jave SE-1.7(jre7)
Clean project or refresh project.
A solution was to create a new project, copy and paste all packages/clases, which worked for a while, but I added UMLet to the project and again...
One possibility is that the UMLet plugin is the cause of your problems. Try a clean Eclipse install without UMLet. (The fact that uninstalling the UMLet plugin didn't fix the problem is in no way conclusive.)
Note that UMLet will run as a stand-alone tool.
BTW, even with the "errors", my project runs without any problem, therefore I know they're not real.
The likely explanation for that is that the compilation errors come from the incremental Java compiler that is built into Eclipse. A different compiler (i.e. the one from your installed / configured JDK) is used to generate the ".class" files.
Multi-catch parameters are not allowed for source level below 1.7
not a solution, to this issue, but if you want to have two exceptions you can code it like this:
try {
// code here
} catch {
// code here
} catch {
// code here
}
it worked for me, instead of having catch (exception1 | exception2 e)

Debugger source line synchronization not working in IntelliJ IDEA Scala plugin

I'm running IntelliJ IDEA 12.1.3 on Windows 8 with the Scala plugin 0.7.264. Scala is installed in C:\Apps\Scala\scala-2.10.1, and that directory is in my PATH. The Scala docs are in C:\Apps\Scala\scala-2.10.1\doc\scala-devel-docs\api. These are manual installs from the .zip files.
Everything seems to work fine except for two things:
First, if the "Run compile server (in external build mode)" settings is enabled (as it is by default), I get this error:
Turning off that setting fixes that for now, but there is another problem. I can run my code in the debugger and see values change in the debugger panel as I single step through the code, but it doesn't synchronize the source file view as I step through.
Normally I'd expect to see the current line being executed turn green, and the green highlight would follow along as I hit F10 or F11 to step through, but it doesn't. I can set breakpoints on source lines and let it run, and it stops at each breakpoint as expected. It just doesn't highlight the source line in green when it gets there.
Similarly, if a source file is not open (either my source code or a library file), and I step into that code, it appears to single-step correctly but does not open the source file at all.
Everything else works fine, like the autocompletes and Shift+F1 to view the Scala docs for the name the cursor is on.
The really odd thing is I had full debugging working briefly. At first I'd installed Scala from the .msi file, so it installed Scala into C:\Program Files (x86)\scala. When I set up IntelliJ to use that Scala installation I did get the green highlight on source lines as I stepped through the code.
The only problem with that setup was that IntelliJ complained about the missing doc\scala-devel-docs\api directory when I'd setup a Scala project, because the .msi installation uses a different subdirectory for the API docs. It was easy enough to fix that up manually in the Global Liraries settings, but I figured I'd try the .zip installation so I could use a directory layout more like what IntelliJ was expecting.
I should have left well enough alone! I even tried going back to that arrangement and still didn't get source line synchronization working again.
At one point I also tried letting IntelliJ do the Scala installation, but that also gave the same results: everything working except source line synchronization in the debugger.
There must be some obvious thing I got wrong, but I'm not sure what it could be. Does anyone have any ideas?
Here's a screenshot from a debug session:
The program is stopped on line 3, as indicated by the values assigned to x and y but not yet to z, and the <init>():3, Main$$anon$1 in the Frames panel. So line 3 should be highlighted in green but isn't.
Here are the relevant settings dialogs:
The above is with "Run compile server" on; as mentioned I ended up turning that setting off. The field values are the defaults, including the -server -Xss1m -XX:MaxPermSize=256m JVM parameters.
I am using the same version of IDEA and the Scala plugin (however on OS X and JDK 6), and I do not have this problem. Does this occur with any of your projects or only a specific one?
Assuming that the OS shouldn't be responsible, the difference is that I use sbt to build my projects. So if you are willing to set up a build.sbt and installing the SBT plugin for IDEA, this might be worth a try.
Although the fancy new compile server should in theory be as fast and smooth as sbt, I find it very pleasant to work with the sbt plugin. You can install it from Settings -> IDE Settings -> Plugins. Next step I also highly recommend is to use the sbt-idea plugin, which is like the complementary to the IDEA SBT plugin—this will allow you to generate the full IDEA project files from sbt (you can have as little as a single scalaVersion entry in build.sbt if you don't need to manage dependencies, so you don't need to learn much of sbt in the first place).
The final step then is to go into your Run/Debug configuration, and change in the "Before launch" section from "Make" to "SBT".
Finally you might get better support for your problem through the JetBrains online forum.

Play Framework + Eclipse: undefined method for ReverseApplication

I'm having a little trouble (more like an annoyance, really) when using the Play Framework with Eclipse.
I'm following this tutorial to get started with Play. In a certain moment in the tutorial, it asks us to type in this code:
public static Result index() {
return redirect(routes.Application.tasks());
}
This works as expected when running the application. The problem is that Eclipse doesn't like it. It says:
The method tasks() is undefined for the type ReverseApplication
While underlining tasks with the dashed red line. Is there a reason for this to happen? I've tried cleaning and compiling the project (through the Play terminal) and refreshing the project in Eclipse, but to no avail.
Is there something I can do about it?
I'm using Eclipse Juno, build 20120606-2254
Thank you so much!
Since the views are Scala code, they are compiled by the Scala compiler (ie your Play console through sbt). So Eclipse cannot compile and find these.
So, your best option is to configure Eclipse so that it automatically refresh the workspace and make sure that the folder "target/scala-2.9.1/classes_managed" is in your build path (it should be done by the "eclipsify" command).
If it does not work after all these steps, try "clean", "compile" and "eclipsify" (for Play 2.0.x) or "eclipse" (for Play 2.1.x) and refresh your projet.
Close and open your project in Eclipse. This worked for me (Eclipse Juno).
None of the previous suggestions worked for me, but when I did a refresh on the target folder, the red underlining on my view references went away.
The Play command used to be called "eclipsify". It is now called "eclipse".
Generally, I do the following and it works pretty well with Eclipse
-at the start of the day, start the play console in your project dir and do 'clean' and 'run'
-open a web browser point to the app (localhost:9000)
-launch eclipse
-make code changes...
-Play will rebuild the app whenever code changes occur. So refreshing the app in
the browser.
-back in eclipse, Refresh the project to reload the files that play rebuild just made.
I know it has been a year since #nico_ekito's answer but just wanted to add this.
Adding /target/scala-2.10/classes_managed and ensuring that Eclipse automatically refreshes the workspace fixed it for me. Thanks #nico_ekito
Using Eclipse Kepler, play framework 2.2.2