It would be nice if there was a "worksheet mode" that allows you to interactively evaluate toplevel statements inside the editor and see the results.
Some challenges:
This feature would be killer for adoption. Worksheets worked pretty darn good in Scala IDE and some people are still hanging on to the tool because of that feature. Everyone wants to have worksheets like the kind you find for Python which is a big reason for the number of people using the language. These tools that make it easy for the masses are the key to greater adoption for Scala.
Adding a few notes from offline discussions with several people including @jvican, @baccata, @alexarchambault
(Brainstorming) We could potentially support "worksheets" in several different forms:
*.notebook.sc: which will have Jupyter notebook semantics where cells are separated by some magic //%% marker comments (like in the python vscode extension). I believe notebook semantics are desirable for use-cases where you have an expensive fixture that you only want to evaluate once (like setting up a database) and then want to iterate quickly after that. Another use-case is media objects (graphs, plots, images, ..).*.worksheet.sc: which will have Intellij/Scala IDE semantics where the entire script is evaluated in one run (no cells) and we place decorators next to each val/var showing the type + runtime value (similar to mdoc).*.sc: regular ammonite scripts that are evaluated by delegating to some command like amm --watch .....*.scala.md: (just an idea) would be nice if it was possible to write markdown files and have the scala code fences evaluated worksheet-style.We wouldn't have to implement all of these, I'm just exploring the possible solution space.
It would be nice to support $ivy and $file from ammonite scripts. This would require something like a new --compile-only flag to ammonite that compiles a script without evaluating it. The --compile-only mode would need to emit the following information:
$file imports.We need the classpath and scalac options in order to provide completions/type-at-point/parameter-hints.
To show the results of evaluating an ammonite script, we could
window/logMessage.amm foo.sc from their favorite terminal.Almond has a nice library API ScalaInterpreter which has a execute method that where we could run individual cells. https://github.com/almond-sh/almond/blob/adb2840e69f63ef6ff25c375b04d7d50c97493a7/modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala#L109-L114. The benefit of this approach is that the user wouldn't need to install almond separately but at the cost of requiring custom development both in the Metals server side and editor client side.
The Python VS Code extension implements in TypeScript on the client side the splitting of code cells via magic #%% comments and submits the code to a running Jupyter server. The implementation seems generic enough that it could be adapted to Scala and the vscode-python team has alluded to adding polyglot support at some point in the future (see https://github.com/Microsoft/vscode-python/issues/5109). This approach has the benefit of requiring less custom work but requires the user to have a jupyter server running on their computer in the background.
I have a feeling it might be good to wait a few months and see if something moves with the vscode-python polyglot support.
Possible implementation approaches:
toString()), it builds a rich runtime data structure with all the instrumented values (range positions, types, runtime values).Similarly to regular worksheets, we could build on top of mdoc to instrument and evaluate code fences inside markdown files. The worksheet mode (*.worksheet.sc) could be treated as a markdown file with only a single code fence.
Just a few comments about features related to notebook support. Thanks for the overview above.
Lots of notebook type concepts are in engineering/math tools like Matlab, Maple, Mathematica etc. A good example I have used is _Mathematica's_ notebooks. Links - http://www.wolfram.com/technologies/nb/ - and - https://reference.wolfram.com/language/guide/NotebookBasics.html
Today of course there is Almond, spark-notebook, and notebook systems in Databricks and the like, let alone the Jupiter and other Python tools.
Useful features:
I would like to see a minimal worksheet system to start with more features later. I think it might be an option to have the dependencies in a generated file/directory and be listed in sbt format or something you can just copy from Maven central if you need to add them. When creating a worksheet, maybe the file could be generated like is done for scalafmt? If you have 3 or 4 worksheets it might be tedious to have Ammonite imports on each but it might be useful to add dependencies directly to the worksheet for experimentation. Perhaps even add the current project classpath for the current project. Just throwing some ideas out.
Have a basic working implementation that
Stream types), diagnostics, cancellation support, and more. I'm sure it would have been possible to achieve similar functionality with ScalaInterpreter from Almond but I am less familiar with that API. A small preview

Will try to open a PR as soon as I get around to clean up the branch.
@ekrich this is a "minimal" worksheet implementation to get the ball moving. The current implementation doesn't provide several features that I would love to support down the road
How to show the type, like intellij and scala-ide?
@robsonpeixoto best to do it with Hover I think.
Most helpful comment
Have a basic working implementation that
Streamtypes), diagnostics, cancellation support, and more. I'm sure it would have been possible to achieve similar functionality withScalaInterpreterfrom Almond but I am less familiar with that API.A small preview
Will try to open a PR as soon as I get around to clean up the branch.