Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement basic worksheet mode using mdoc and text decorations #1041
Previously, there was no way for users to interactively explore APIs and evaluate small programs when coding with Metals. This commit adds a new "worksheet mode" for files with the extension
Simple code usually compiles and evaluates pretty fast, even if you do a bit of I/O
Completions, type at point, parameter hints work as expected
Robust against slow programs
Slow running programs can be cancelled with a single click, even infinite loops.
Compile errors work as expected
Infinite stream are evaluated lazily
Thanks to http://www.lihaoyi.com/PPrint/
Runtime crashes are reported with red squiggles
A full stack trace is included in the error message.
Hover message for large values
Kudos to @Duhemm for pioneering Scala worksheets in the Dotty Language Server (http://dotty.epfl.ch/docs/usage/worksheet-mode-implementation-details.html). The implementation in this PR is heavily inspired by worksheets in the Dotty Language Server.
Big thanks to @gabro for exploring decorations in the VS Code API and giving lots of useful feedback.
Previously, there as no way for users to interactively explore APIs and evaluate small programs. This commit adds a new "worksheet mode" for files with the extension ".worksheet.sc". These files allow toplevel statements and the statements are evaluated on file save, with evaluated results displayed inline alongside the code using a new "Decoration Protocol", a LSP extension. Fixes #1040.
There are several features that are not implemented in this PR but would be super cool to support in the future
Previously, worksheets wouldn't pick up the latest classpath in the build. Now, we reset the worksheet classpath when build targets finish compilation.
Previously, we had custom queue for evaluating worksheets. Now, worksheets are evaluated as part of the normal compilation.
This looks amazing, just a few questions about the code. The rendering logic doesn't seem very maintainable and wasn't able to properly review that.
I would also look into how we can provide worksheet experience for other clients than VS Code out of the box. I was thinking about code lenses, but that might not be the best idea after talking with @olafurpg . What about using workspaceEdit with adding the results as comments? This is also not ideal, but I worry about adding LSP extensions that there will be no one to actually implement those for anything else.
We could default to mechanism like:
The problem is that workspaceEdit will not save the file, so somehow we need to make the experience better for users.
@tgodzik I think this approach is worth exploring as a fallback for other editors. We might be able to include a magic marker for the inserted comments so it's easy to tell which comments are generated by worksheets and which comments are written by the user.
I would normally ignore the flaky test failure (it was passing before with the same code) but the failing test case is from
I'll try to investigate...
Ignoring unrelated flaky test failure
X tests.TreeViewLspSuite.no-op 2280ms tests.TestFailedException: failed assertion at /home/runner/work/metals/metals/tests/unit/src/test/scala/tests/TreeViewLspSuite.scala:487 =========== => Obtained =========== """|b/ + ======= => Diff ======= --- obtained +++ expected @@ -1,1 +1,1 @@ -b/ + +