Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: Scala worksheet don't pick up code changes without restart

If I have the contents of an object imported at the top of a Scala worksheet in Intellij, when I add new things to the object, they cannot be found in the worksheet. Even after I build the project and reevaluate the worksheet, it can't find the new property. Autocomplete works. If I quit and restart IntelliJ it works.

This is the error:

java.lang.NoSuchMethodError: Arith$.foo()Ljava/lang/String;
    at #worksheet#.get$$instance$$res6(ArithWS.sc:15)
    at A$A1$.main(ArithWS.sc:41)
    at #worksheet#.#worksheet#(ArithWS.sc)

Weirdly, it seems to compile, but fails at runtime. This is a normal SBT project. IntelliJ 2017.2.5, Scala 2.12.3. Selecting the "Make project" checkbox doesn't help. Actually no combination of checkboxes makes it work. No amount of rebuilding the project or the worksheet helps either. Only restarting IntelliJ will get the worksheet to pick up the new code.

Example project code in Arith.scala:

object Arith {
  val foo = "foo"
}

Example worksheet ArithWS.sc:

import Arith._

foo
like image 368
postfuturist Avatar asked Oct 19 '17 02:10

postfuturist


People also ask

How do I use Scala code in IntelliJ?

To install Scala plugin, press Ctrl+Alt+S , open the Plugins page, browse repositories to locate the Scala plugin, click Install and restart IntelliJ IDEA. Now you can successfully check out from VCS, create, or import Scala projects.


1 Answers

This seems to fix it, though I would love to know why the default setting is broken, or what this undocumented setting does: Go to File -> Settings -> Languages & Frameworks -> Scala -> Worksheet (tab) . Unselect "Run worksheet in the compiler process".

like image 104
postfuturist Avatar answered Sep 20 '22 21:09

postfuturist