9
votes

I can not use my classes from Scala worksheet in IntelliJ CE with Scala plugin.

I do the following:

  1. Create Scala SBT project.

  2. In src/main/scala create package test1.

  3. In this package create class

package test1
class TestClass {
}
  1. In the same package create Scala worksheet ws1.sc, inside it create object ws1, inside it put a couple of expressions. It works.

Screenshot 1

  1. When I add new ScalaTest to object ws1, IntelliJ adds import test1.ScalaTest, but evaluation of worksheet does not work.

Screenshot 2

If I add package test1 to my worksheet, it does not work at all, with warning "Package name doesn't correspond to directories structure, this may cause problem with resolve to classes from the file"

Screenshot 3

Is there any ideas how to use my classes from worksheet?

2
AFAIK, classes defined inside Scala worksheets cannot be referenced from outside the worksheet. Worksheets are for quick, throwaway testing only. Why don't you create regular Scala classes and objects?Madoc
Nope, ScalaTest is regular class, it is defined outside worksheet, look at screenshot.tse
How exactly does evaluation of the worksheet fail in step 5? - I see no problems there.Madoc

2 Answers

8
votes

You can use eclipse compatibility mode:

Settings → Languages & Frameworks → Scala → Worksheet → use "eclipse compatibility" mode

4
votes

You must tick "Make project" next to the "Interactive mode"