Scala Worksheet

We are announcing start of Scala Worksheet feature support. It’s available in scala plugin for Leda from v.0.6.368.

A worksheet is a scala file with .sc extension which you can run and  get evaluation results in a special view appeared in the editor.

Create worksheet by right-clicking on your Project and choosing ‘New’ -> ‘Scala Worksheet’.

Just type your code, press ‘Evaluate worksheet’ button and results appear.

Evaluation of Scala Objects is also supported.

‘Worksheet’ tab is available in ‘Project setting’ -> ‘Scala’. You can configurate output length before line break.

All features of Scala editor are supported because worksheet file is treated as simple scala file.

Comments below can no longer be edited.

36 Responses to Scala Worksheet

  1. Avatar

    Robin Cateran says:

    December 4, 2012

    Good work! After using Eclipse for the Functional Programming in Scala course recently, I found this to be a really nice feature. Thanks guys!

  2. Avatar

    Jan says:

    December 4, 2012

    Thanks ! Will be very useful indeed. 🙂

    Btw, does this mean the “fast” compiler will be fixed for Leda ?

  3. Avatar

    Erik Pragt says:

    December 4, 2012

    Very nice indeed. Will this also become available for Groovy? Or maybe even Java? Sometimes it’s really handy to be able to type in some code and see the results of that.

    • Avatar

      Mark Hammons says:

      December 4, 2012

      I believe the Scala worksheet is powered by scala’s REPL, so I don’t know if java would be as able to get the worksheet functionality.

      On a different note, will people who bought the personal licence during the back to school sale be able to upgrade to Leda for free?

    • Avatar

      Ksenia Sautina says:

      December 12, 2012

      However there is special issue for Java Worksheet: http://youtrack.jetbrains.com/issue/IDEABKL-6587
      You can vote for it.

  4. Avatar

    Anna says:

    December 4, 2012

    Great! Happy to read it! But unfortunately my scala plugin has v.0.5.983 and can’t be updated to v.0.6.368 yet. Hope it would be possible soon.

  5. Avatar

    Konrad says:

    December 4, 2012

    Awesome, now there’s no reason at all to show eclipse to people at Scala trainings I do! 🙂

  6. Avatar

    Jem Mawson says:

    December 4, 2012

    Thank you to the beautiful people who made this happen.

  7. Avatar

    Trond says:

    December 5, 2012

    This is truly a great feature! However – it is painfully slow! Is there some trick to make the worksheet work faster?

    • Avatar

      Matthew Pocock says:

      December 8, 2012

      Same here. It’s a wonderful feature, and means that I don’t have to reach for eclipse for this kind of thing, but on both my systems it is excruciatingly slow. Ideally, it needs to be as-I-type, or at least interactive. I’m waiting several seconds for each line to be evaluated. The same code in a REPL session is instantaneous.

    • Avatar

      Ksenia Sautina says:

      December 12, 2012

      Yes, currently we have to make worksheet much faster (for example, not to stop JVM after run to avoid running JVM and loading classes cost).

      • Avatar

        Peter Britishton says:

        May 3, 2013

        Amazing feature indeed. But is there any update on the progress on improving the speed? It’s still painfully slow 🙁 (Just bought the IntelliJ Ultimate for scala development; amazing IDE, but faster worksheet is a *must*! 🙂

    • Avatar

      Fabio says:

      October 4, 2013

      I will add my thank you, and also that alas the Worksheet is still painfully slow. Is there a way to make it evaluate on save?

  8. Avatar

    Santeri Hiltunen says:

    December 11, 2012

    This is a great first version. What it really needs is more speed as others have noticed. It would also be nice if the worksheet would be evaluated every time it’s saved (either by the autosave or manually) but this depends on speed improvements. These additions/fixes would really make it up to par or even better when compared to worksheets in Scala IDE.

    Keep up the good work!

  9. Avatar

    Bilbo says:

    December 11, 2012

    Great stuff.

    One improvement: if the project you’re in has compile errors, the worksheet doesn’t function. It seems the worksheet tries to compile the whole project every time; maybe this is why it’s so slow. The Eclipse version works fine without you having to fix the whole of the rest of your project.

  10. Avatar

    Avatah says:

    December 12, 2012

    I cannot use scala worksheet. When trying to run it it always gives me an error:
    Error running WS
    Cannot run program “/usr/java/latest/bin/java” (in directory “/home/avatah/projects/myproject”): java.io.IOException: error=7, Arguments list too long
    Probably classpath of my project is too long

    • Avatar

      Ksenia Sautina says:

      December 12, 2012

      Check the .idea/workspace.xml file and switch the dynamic.classpath option to “true” if it’s needed.
      By the way the best way to report such problems is our issue tracker: http://youtrack.jetbrains.com/issues/SCL

  11. Avatar

    Yagiz says:

    December 27, 2012

    This is really great. Last time I checked it, it was pretty slow. Is it planned to use fsc?

  12. Avatar

    levi says:

    December 27, 2012

    This is seriously awesome. Installed it and having a lot of fun. It may be the best way to learn Scala. Zero setup required and it works pretty well. I think it would be nice if it were to be faster, but I’m sure there are issues with essentially redefining all of the functions that are left in worksheet everytime IntelliJ has to be invoke the repl. Not sure though. Either way, fantastic work making programming more enjoyable!

  13. Avatar

    Rao Venu says:

    January 26, 2013

    Is there any possibility that this will be backwards compatible with IDEA Ultimate 11?
    I am not in a position to upgrade to 12 but would love to have this feature.

    • Avatar

      Ksenia Sautina says:

      January 30, 2013

      Unfortunately, Scala Worksheet is available only in IDEA 12.

  14. Avatar

    Ben says:

    March 26, 2013

    It’s a shame I can’t import classes from the current project. The names will autocomplete when typing in the worksheet, but when running, the compiler just gives the “object mypackage is not a member of com” error.

    • Avatar

      Ben says:

      March 26, 2013

      Installing the SBT plugin, and compiling with SBT from within IDEA before executing the worksheet, seemed to fix this.

    • Avatar

      Tomek Kozlowski says:

      October 14, 2014

      mark “Make project”, it rebuilds all your staff

      • Avatar

        JP says:

        September 24, 2016

        thanks it helped!

  15. Avatar

    Jim says:

    March 29, 2013

    Doesn’t seem to work on Mac. I can edit the worksheet, however there is no output pane/area.

  16. Avatar

    Michael says:

    April 5, 2013

    Unfortuantely worksheets do not work with namespaces/packages. Putting the worksheet in a package/subdir e.g. “examples” and defining a class in the worksheet does not work.

    Content of the scala worksheet ws.sc inside the examples dir:

    class Foo {
    val a = 10

    new Foo().a

    Compiles, but generates no output.
    Adding a package statement leads to the IDE warning that the package structure does not correspond to the directories structure, compiling results in an error (illegal start of definition).


    • Avatar

      min says:

      May 27, 2015

      I found the solution for this type of behaviour is to copy the class into the curly braces of the object. so it would be something like this:

      object test{
      new Foo().a

      class Foo {
      val a = 10
      } // class is inside of the object

      • Avatar

        Dan says:

        April 3, 2017

        Had the same issue and this resolved it.

  17. Avatar

    Brent says:

    May 13, 2013

    Unlike the Eclipse Worksheet that immediately updates when the file is saved, the IdeaJ Scala Worksheet plugin only re-evaluates the worksheet when you press Cmd-Opt-W.

    Note also that the SBT plugin is required.

    And… it’s very, very slow to update. The Eclipse Scala Worksheet updates immediately, while the Idea Scala Worksheet launches an external build, Scala process, then updates the results approx. 30s later.

  18. Avatar

    Jim Pivarski says:

    June 25, 2013

    Um… This is not a worksheet. I’ve just installed IDEA and Eclipse for the sake of their Scala Worksheet plug-ins, puzzled through all the configuration steps, and only when everything was finally working did I find that they’re not even worksheets. Has anyone ever used Matlab, Mathematica, Maple, Sage, or even Emacs lisp-interaction mode?

    A worksheet is when you have a REPL running in the background with a front-end that alternates between user inputs and kernel outputs. Inputs are intended to be modified and re-run many times, but the REPL is not restarted, libraries are not reloaded, and if a no-longer-existing input line modifies the kernel’s state in some confusing way, that’s your own darn fault.

    The Eclipse Scala Worksheet plug-in is not even a REPL. You save the file and it evaluates the whole file in non-REPL mode (everything has to be in an object or a class). If you make a change, it re-evaluates everything from a clean slate, which is less confusing, but a show-stopper if some of your initial steps take a long time.

    The IDEA Scala Worksheet plug-in is a REPL (you can “println” outside of any objects or classes), but it cleans the slate every time you run. Not to mention that it takes 30 seconds to run each time, which makes even “println” a show-stopper. Is it re-loading libraries as part of the slate-cleaning? It would be better to turn that off. Let the user be confused: worksheets are like a first sketch of a program with lots of messy changes that will get cleaned up later.

    Both have the same strange format: input on the left, output on the right, with no geometric connection between the input and output.

    Maybe I should look at Scala Notebook again (https://github.com/Bridgewater/scala-notebook), but I’d rather use a fully featured editor, not a web browser, because worksheet analysis sessions grow up in fits and stages into real programs. Maybe I have to go back to Emacs and write a mode for it.

  19. Avatar

    Dave Hill says:

    August 16, 2013

    have freshly installed the latest Scala plugin, opened a worksheet, and get no output when I evaluate it.

    running IDEA 12.1.3 ultimate, JDK 1.6.0_33, scala-2.8.1.final, Win 7 pro

    first tried it inside a package (but no package declaration in the worksheet) then moved it out of packages to the root as some users here seem to be describing, no joy

    any suggestions?


  20. Avatar

    Hanxue says:

    November 15, 2013

    The worksheet parser does not recognize a statement that is split over 2 lines. For example

    val strRepr1 = aList.map(u => u.toString)
    .reduceLeft( (u, v) => u+","+v)

    will result in a List[String], instead of a String (with each element in aList concatenated with “,”)

  21. Avatar

    Angel Ruiz says:

    May 15, 2014

    There is a problem with the code editor scrolling in this worksheet mode. If I have code that do not produce any output at the bottom of my .sc file, I cannot scrolldown once the last output is showed in the right pane.

    • Avatar

      Valentin Rusu says:

      May 26, 2014

      Same for me here!

Discover more