Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala, Cats, Intellij IDEA: fix syntax & compile errors?

Tags:

Using the Cats library for Scala in IntelliJ IDEA leads to errors even if terminal SBT works. Can we fix this? Or some workaround that isn't switching editor?

like image 727
ticofab Avatar asked May 29 '18 15:05

ticofab


People also ask

How do I change the Scala version in IntelliJ?

In most cases your project JDK is not compatible with Scala or sbt version, try to change the Scala Compile Server SDK. Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.


1 Answers

Cats seems to work fine on my IntelliJ 2018.1.4. If it is working in the terminal but not in IntelliJ, it could be because of using in-built IntelliJ compiler. Have you tried enabling Use sbt shell for build and import, which delegates building to SBT:

  1. Open sbt projects tool window: View | Tool Windows | sbt
  2. Click sbt settings icon
  3. Select Use sbt shell for build and import (required sbt 0.13.5+)

Use sbt shell might resolve compilation issues, however note that in-editor error highlighting might still give false positives because it uses custom-built typechecker.


Metals is an alternative that uses Scala proper for both compilation and in-editor error diagnostics.

like image 61
Mario Galic Avatar answered Sep 28 '22 18:09

Mario Galic