IntelliJ IDEA Scala plugin's syntax highlighting displays Scala packages in red - scala

This is a bit weird, I've got IntelliJ IDEA 10, a fairly recent Scala plugin on it and sbt 0.7.7. I've been using the same setup on the same project for a while and syntax highlighting worked perfect.
After a few clean/compiles from sbt (I'm not really sure about the action), everything from Scala._ is red. For instance, List() is red but when I import scala.collection._ it gets fixed. The project compiles without any problems in both IDEA and SBT. What may be the problem?
(new/other projects are OK on the same setup so I guess I've messed up something but I have no clue where to look for it)
Thanks

I've never found a single solution to this, so i generally try all the things.
sbt gen-idea (to recreate IDEA project meta-data)
File > Invalidate Caches ... > Invalidate and Restart
After invalidating caches, upon restart IDEA will re-index all of your class files.
Usually I'll try
sbt> clean
sbt> gen-idea
Then if it didn't work go for invalidating caches. If that still doesn't work (and it almost always does) try deleting the following directories and then perform #1/#2 from above again:
target
project/target
.idea
.idea_modules

at project Settings, add the jars to its dependencies of IDE, then you will get the red away.
SBT is one thing, IDEA is another, they use their own way to compile scala. some sbt plugin for idea is also something that just hook sbt command line to idea's panel.

This sometimes happens to me when the SBT and IDEA projects get out of sync. Simply run the SBT Idea processor again - this regenerates your Idea project files.

Related

IntelliJ "extracting project structure from sbt"

Okay. So i ahve this problem concerning itelliJ revolving around SBT and Scala.
The problem is that intelliJ cannot correctly import the project, and i am left with an intelliJ that recognizes only false syntax errors and which cant compile from the "run" bottom integrated within the IDEA.
When I start IntelliJ/Open the project, the SBT goes to work and tries to index the project, after which it fails, returning me multiple errors.
Extracting structure failed: Structure file /tmp/sbt-structure.xml is empty
Picture of additional erros
The thing is, that the code works, using the terminal it can both compile and run!
I feel like i have traversed the internet and done multiple things including:
Reload SBT.
Try to Import the project with SBT.
Reinstall plugins.
Restart and invalidate cahces.
Thanks in advance!

IDEA says a dependency is missing, SBT disagrees

my issue seems similar to Getting IntelliJ IDEA understand SBT dependencies
except I'm using sbt 1.4.4 ,and the plugin suggested in that question no longer appears to work (it requires sbt version 0.13.x, and last commit to that plugin was 7 years ago)
is there anything similar that might work with more recent versions of sbt, or some other way to get intelliJ to work?
It only seems to affect 2 dependencies, all other dependencies works fine, thing is, i really need those 2 dependencies.
I'm on Linux, should it matter, a colleague opened the same code on Mac, and had no issues, however I've tried clearing every cache i could think of, reinstalled IDEA, rebooted twice, changed idea settings to use sbt shell for everything, nothing and everything in between. I've tried to rebuild with sbt version override enabled and/or disabled.
I dont get any errors from intelliJ rebuilding the project, but the editor still insists that some dependencies does not exist!
I'm out of ideas, how can I fix IDEA?
First identify the path to problematic dependencies by executing
sbt 'show dependencyClasspath'
which prints out something like
Attributed(/home/picard/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/mouse_2.13/1.0.0/mouse_2.13-1.0.0.jar)
Next in the following order
sbt clean the project
invalidate caches
Exit IntelliJ
nuke your project's .idea directory.
Now say mouse was the problematic dependency, then remove it with
rm -fr /home/picard/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/mouse_2.13
Finally reimport the sbt project which, if you have the shortcut setup, from project's root directory
idea .
and let sbt refetch the missing dependencies and let IntelliJ reindex them.

IntelliJ show errors in scala source files but the (maven) project compiles successfully

When I open a maven module with scala code (link) which compiles and runs fine, I get bad error highlights:
Code-complete seems broken as well. How to fix this? (I don't want to switch to SBT since I only want this one module in the project to use scala, and I've tried the "Invalidate Caches / Restart" fix suggested here in vain.)
It is a known problem in IntelliJ with Scala because of the complex type system of scala.
I mostly use sbt. If I encounter such problem, first I compile it with sbt in the command line, most time wrong error highlights disappear.
If this does not help, clear IntelliJ cash and restart it (File -> Invalidated Caches / Restart).

Why does IDEA report errors for build.sbt in a new sbt project?

I'm running IntelliJ 13.1.5 community edition. I've got JDK, Scala, SBT installed. The JAVA_HOME, JDK_HOME, SCALA_HOME and SBT_HOME variables are set. If I create a new SBT project, after initial sbt refresh, I get this:
The thing compiles and runs fine, even if I add dependencies, but the file itself shows tonnes of errors. F4 settings show empty SBT module stuff:
I then installed https://github.com/mpeltonen/sbt-idea and ran sbt gen-idea in the project folder. This created a bunch of files, and reloading the project, the reds in the sbt file went away.
This is on my laptop. However, on my work machine, simply creating a new project works fine, and the sbt file isn't filled with red. Can't seem to figure out how that machine's different. Any pointers on how to resolve this annoying issue?
In case IntelliJ IDEA struggles a bit with caching, try the first and if still not working the second should definitely do the trick:
File -> Invalidate cache and restart
Close IDEA, delete .idea, re-import your project
I was also getting highlighted errors in all of the build.sbt file.
What fixed it was to select to Download "Sources for SBT and plugins" in the Import Project from SBT window.
Please, check if you added the “scala-library*.jar” to Scala compiler library
This link might be helpful:
http://blog.jetbrains.com/scala/2010/09/02/project-configuration-explained/
If you are using windows or linux, please also see:
http://confluence.jetbrains.com/display/SCA/Setting+up+Scala+plugin+project+in+IntelliJ+IDEA
Update on 2020, Apr
This works for scala 2.13 and Intellij 2020.1 when:
sbt files has error
project structure is wrong
Reason is 'External libraries' from sbt is not loading for IDE.
To do so, similar to old version: https://www.lagomframework.com/documentation/1.6.x/java/IntellijSbtJava.html
1. rm -rf .ida
2. Click Menu item: Open... to pick the project directory
If not working, I assume you need to setup Global SDK for intellij by
cmd+; and pick the path of scala.
In case of mac,
brew install scala normally echo out the path /usr/local/opt/scala/idea
Let ide browse to this path by holding cmd+shift+G to open path.
IDE should find the path like /usr/local/Cellar/scala/2.13.1/idea/lib/scala-library.jar and scala-compiler.jar and scala-reflect.jar
There might be better way to do the global scala setting though.

IntelliJ show errors in scala source files but the project compiles successfully

I'm working with project in intellij IDEA IDE based in maven. I can perform all maven goals but IntelliJ is showing a lot of errors in the source code like bellow:
Everything worked fine a few hours ago. I don't understand why the IDE continue
showing errors. When I rebuild or compile the entire project (CTRL + F9) or a single
scala class I always receive a success message like that:
I already had configured scala plugin before, so I don't know what is happen.
thanks for your help
Sometimes the IntelliJ cache gets corrupted. You can fix this by the following:
File > "Invalidate Caches / Restart"
After choosing "Invalidate and Restart" when prompted, IntelliJ will restart and rebuild its cache.
If IDEA has lost track of obviously correct types such as Database or DateTime it probably means the configuration of the project is wrong or corrupted. Most commonly it does not have the required 3rd part dependencies such as Joda Time.
If you're not already doing so, define your project solely in SBT and use the sbt-idea plug-in to produce your IDEA project definition. Then whenever you change the project dependencies, re-run gen-idea to regenerate your IDEA project files. No muss, no fuss.
There are many bugs raised in jetbrains's bug tracker for this. I suggest you raise some bugs or vote for existing ones.
It loos like the problem you have is with the type aware highlighting which is worse than useless.
thanks for your responses.
I solved this problem importing the project again.