Debugger source line synchronization not working in IntelliJ IDEA Scala plugin - scala

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.

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.

xdebug/netbeans won't stop at any breakpoint other than in Joomla index.php

I'm a newbie with IDEs, I used Eclipse so far but more like an fancy text editor. I now switched to Netbeans and set it up for Joomla extension development, for which I followed the steps in various tutorials.
Everything works great except debugging. I set up xdebug and it works if I have breakpoints in the Joomla index.php file, but breakpoints in the php files of my component (for example in on e of the model functions) were just ignored.
My setup:
Joomla 2.5
Netbeans 7.4
XAMPP 3.1
xdebug
In both eclipse and netbeans, a prerequisite for debugging is that the project is built.
"Building" doesn't do anything real: php code is not compiled. But it allows the IDE to build a dependency tree, validate the code, allow code completion and follow execution flow from one class to the next.
To build, in eclipse either right click on the project or choose Project/Build from the menu. I have set Build automatically so the resources stay in sync while I work:
I encountered with the same problem, but solution is rather tricky. Actually netbeans stops on breakpoints but no all lines are eligible for breaking. When you put breakpoint wait a little, if beside green square there appears black arrow pointing down then it is OK, otherwise try some other line.

AspectJ causing "Editor does not contain a main type" error

After installing the AspectJ Development Tools into Eclipse, the "Run" button and the Ctrl-F11 shortcut both become nearly useless: using them (or the Debug button) will throw an "Editor does not contain a main type" error message, even for projects that do not require a main type to be present (eg. Android application projects). Standalone Java projects with a proper main type defined work fine - so it seems AJDT is forcing Eclipse to check for a Java main() without checking the project type first. Whether or not the project is an AspectJ project makes no difference, either.
The problem only appears when the file you are currently editing has either ".java", ".aj" or ".class" anywhere within its filename (note: it doesn't actually have to end with those extensions, as long as it's anywhere in there - readme.txt will work, readme.java.txt won't).
Two ways I've found to work around this - regardless of whether or not it's an AJ project - after installing AJDT is:
Select a file within your project in the Package Explorer whose name doesn't contain .java, .class or .aj, and then hit Run (the Package Explorer has to remain active and selected).
Create a new Run Configuration for your project, and use it to launch your project. This still adds a pointless extra step, as well as being impractical for those who work with a lot of projects.
I've tried this on both Eclipse Juno and Helios (Windows XP x86 as well as Win7 x64), the result is the same. While it might seem like nitpicking it certainly isn't: AJDT is hijacking the most frequently used function of the IDE.
I've resorted to having two different Eclipse installations with their own separate workspaces on my work PC, one with AJDT installed, and one without, so I can use the IDE properly when I'm not working on anything AJ-related. Since my company is working on a project that would require other developers to install AJDT into their IDEs, this is a significant issue for us that goes beyond our own loss of time - I can't imagine a lot of developers would be willing to put up with a significant bottleneck being added to their workflow for absolutely no reason at all. So most likely, they will just ditch our product instead!
Update: This has been identified to be a bug inside AspectJ, and has been reported to the AJ development team. You can keep track of it here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=399660
As of this writing, the bug has already been partially fixed, restoring Run functionality to non-AJ-enabled projects.
I was just coming on this site to ask the same question. While I don't have an answer for why this is going wrong, I have a workaround which is helping me currently:
Go to Preferences > Run/Debug > Launching and select Always launch the previously launched application. This will introduce bearable behaviour when working on a single project. You will need to manually create a run configuration for your main class.

Compiling in Eclipse/STS produces no output

I'm a Visual Studio .NET developer who's trying to switch to Eclipse/SpringSource Tool Suite, so I get stuck on probably simple problems. Please bear with me.
I'm working on a Spring MVC project associated with an Apache Tomcat server. If I right-click the server and choose Start (alternatively Package Explorer->right-click project->Run As->Run on Server), my project is compiled and started. Compiler output is shown in Console window. Fine.
But if I simply want to compile the project without running it, I try selecting Project->Build All, Project->Build Project, or Project->Build Working Set. Nothing happens, no screen output, nothing -- despite having non-compiling code.
I expected to see the compiler errors on screen, preferably with the errors highlighted in the code. For what it's worth, I have deselected Project->Build Automatically. Anybody knows what I should do?
Eclipse and STS use incremental compilation. So, every time a file is saved, it is automatically compiled (as well as all files dependent on it). When you deselect Build Automatically, then yes, you will need to explicitly build, but this will still be an incremental build (ie- only the changed files and dependencies).
See here for a bit of a discussion on how incremental building works in Eclipse: http://www.eclipse.org/articles/Article-Builders/builders.html