Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: introduce a new jupyter notebook based REPL #1016

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

compnerd
Copy link
Member

VSCode has introduced a native jupyter notebook API. Wire up a "kernel" for Swift to provide a native REPL experience within VSCode. This is primarily a PoC implementation that demonstrates how such an implementation could work.

The primary limitation in the current implementation is the IO processing in the LLDB REPL. We can apply a heuristic to capture the error message (termination on an empty string), but do not have such a heuristic for the output and currently only capture the first line of the output, leaving the remaining output in the buffer. Improving the stream handling would significantly improve the experience.

Copy link
Contributor

@plemarquand plemarquand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool. I've aded a few comments aimed at getting CI passing while I try it out more in depth.

src/repl/REPL.ts Outdated Show resolved Hide resolved
src/repl/REPL.ts Outdated Show resolved Hide resolved
src/repl/REPL.ts Outdated Show resolved Hide resolved
VSCode has introduced a native jupyter notebook API. Wire up a "kernel"
for Swift to provide a native REPL experience within VSCode. This is
primarily a PoC implementation that demonstrates how such an
implementation could work.

The primary limitation in the current implementation is the IO
processing in the LLDB REPL. We can apply a heuristic to capture the
error message (termination on an empty string), but do not have such a
heuristic for the output and currently only capture the first line of
the output, leaving the remaining output in the buffer. Improving the
stream handling would significantly improve the experience.

Co-authored-by: Jeremy Day <[email protected]>
@compnerd
Copy link
Member Author

compnerd commented Sep 2, 2024

@plemarquand anything to do here to move this along?

@plemarquand
Copy link
Contributor

@compnerd I did finally get a chance to try this out last week and found that the "Evaluate in REPL" functionality didn't work as I expected. Putting the cursor on print("Hello") and selecting > Swift: Evaluate in REPL brought the code in to a cell in a new notebook but didn't evaluate it, and there doesn't seem to be a way to evaluate or delete the cell. I also get a toolbar of buttons like Clear All, Variables, Export, etc but these aren't hooked up and so don't do anything.

If I write the same code out in the input window at the bottom of the notebook and execute it, it does get evaluated as I expect.

I imagine there is work we could do here to hook everything up to the REPL hosted by the extension, but I think a better long term approach is to build a real Swift Jupyter kernel with something like xeus, likely as its own standalone repo, and then load in or depend on it in the VS Code extension. This would make it a "first class" experience that would be portable to other Jupyter environments. The Swift REPL could still power the kernel as you have it designed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants