A few days back Jetbrain IntelliJ almost made it impossible for me to write code at work. The IDEA was showing me errors in the editor, but the code was compiling just as fine without any issues, also, the auto-completion was gone, until I found a solution for it. For me, the root cause was an improper import of the project.

I use a macOS based computer for all the development related work, and hence this article has only been validated on a macOS/Mac OS X based machine. However, if you are facing the same editor-error problem on a Linux OS as well, then please try the following methods and let me know in the comments section below whether it worked for you or not.

Solutions to IntelliJ Editor Error Issue:

One of the following solutions might work for you as it is dependent on the type of configuration you have with the IntelliJ. All these methods are for SBT based projects such as those based on Play Framework.

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:

Note: Please check for the latest version at the plugin’s GitHub page.

Save the file using the options in your editor, and then go to your project directory and execute the following command

$sudo sbt gen-idea

If all goes well, this will download all the required project and third party libraries for IntelliJ to behave normally and as expected. Also most probably, after a restart, things will come back to normal

 3. Invalidate and Restart your IntelliJ

For some, this might just work out of blue. All you have to do is go to File Invalidate Caches/Restart and click on Invalidate and Restart. After the restart, Idea will index all your files again, and that’s it. You will have the full feature set restored, also make sure that the Power Save Mode is OFF.

4. Check Project Root Directory

You need to be a little careful with this step, as this might ruin your entire project structure. To confirm you have correct project structure, go to File > Project Structure or press ⌘+; to open the interface. Now, under Project Settings, there’s going to be a section called as Modules, over there make sure you have right sources listed. If not, then click on + Add Content Root and browse to your project’s root directory. Once done, execute the second step of restarting and invalidating caches.

IntelliJ IDEA Root Sources
Intellij IDEA Root Sources Folder

It never worked for me, but I have seen people fixing all of their IntelliJ IDEA editor related problems using this one little trick.

5. Build your Project:

In this method, go to Build and select Build Project or press ⌘+F9 to make the project. If this method is for you, then IntelliJ IDEA will get all the necessary project files and compile/build your project fixing issues of false errors with the editor.

Final Word:

This is all I have to write in this article; I hope it helps you solve this hair pulling issue. Please do share so that other people can also fix their problem without wasting much of time. Drop a comment for any issues.