Skip to content

Add --rpc option for roc repl#9923

Draft
ageron wants to merge 4 commits into
roc-lang:mainfrom
ageron:repl-rpc
Draft

Add --rpc option for roc repl#9923
ageron wants to merge 4 commits into
roc-lang:mainfrom
ageron:repl-rpc

Conversation

@ageron

@ageron ageron commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR adds the --rpc option to roc repl.
It starts the REPL in RPC mode, where the inputs and outputs are JSON objects. For example {"method": "repl.start"}.

Methods:

  • repl.start
  • repl.stop
  • repl.reset
  • repl.evaluate
  • repl.autocomplete
  • repl.inspect

For example:

% roc repl --rpc
{"method": "repl.start", "id": "req001"}
{"session_id":"68da396c-9302-4d2a-a800-a3b644665c68","id":"req001"}
{"method": "repl.evaluate", "params": {"session_id": "68da396c-9302-4d2a-a800-a3b644665c68", "code": "2 + 2"}, "id": "req003"}
{"result":"4.0","stdout":"","diagnostics":null,"id":"req003"}
{"method": "repl.stop", "params": {"session_id": "68da396c-9302-4d2a-a800-a3b644665c68"}, "id": "req004"}
{"success":true,"id":"req004"}

@rtfeldman

Copy link
Copy Markdown
Contributor

@ageron hm, I'd really rather not introduce JSON into any of our CLI or compiler outputs... 😅

Is there another way we could do this?

@ageron

ageron commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @rtfeldman ,
Isn't that how the LSP works? If we want external tools to provide a REPL UI (such as Jupyter Notebook), then we need some kind of programmatic interface. We could just parse the REPL UI, but that's pretty brittle (e.g., if a program outputs » the tool will think it's a prompt). Let's continue this discussion on Zulip.

Comment thread src/cli/main.zig

// Set version to 4
bytes[6] = (bytes[6] & 0x0f) | 0x40;
// Set variant to RFC 4122

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4122 is technically obsoleted by https://datatracker.ietf.org/doc/rfc9562/.

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.

3 participants