Skip to content

docs(plugins): add Node.js JSON-RPC example and align host API 0.19.0 - #387

Merged
fcoury merged 1 commit into
mainfrom
docs/rpc-plugin-examples
Oct 14, 2026
Merged

fcoury merged 1 commit into
mainfrom
docs/rpc-plugin-examples

Conversation

@fcoury

@fcoury fcoury commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Red's JSON-RPC plugin protocol (#380) and JSON Workbench (#381) ship in the upcoming v0.9.0 release against host API 0.19.0. While examples/rpc-hello-plugin provides a reference Python implementation, developers building JSON-RPC plugins in JavaScript/Node.js need an equivalent runnable package that demonstrates newline-delimited stdio framing, decimal-string revision/ID preservation, Unicode-scalar range indexing (Array.from(text).length rather than UTF-16 .length), and initialized gating without introducing an external SDK. examples/README.md also retained pre-consolidation 0.21 and 0.26 host API numbers.

What Changed

  • Added examples/rpc-hello-node-plugin/ (red-plugin.toml and plugin.mjs), a standard-library Node.js implementation matching examples/rpc-hello-plugin/ across all 13 commands and file:saved event handling.
  • Updated examples/rpc-hello-plugin/ to add Windows [rpc.commands] entries (python), enforce waiting for initialized before calling host methods, and support optional suffix arguments on RpcApply that replace line 0 using Unicode-scalar offsets and expected_text preimage verification.
  • Updated examples/README.md to reference examples/rpc-hello-node-plugin/ and align host API version numbers with 0.19.0.
  • Expanded tests/test_rpc_example.py to run the shared conformance suite against both the Python and Node.js examples, covering manifest/handshake agreement, initialized gating, large decimal-string revisions/IDs (> Number.MAX_SAFE_INTEGER), non-BMP Unicode-scalar edit ranges (🦀), stale-revision (-32002) error recovery, panels, statusline, config/storage, pickers, and shutdown/exit.

How to Test

  1. Run python3 -m unittest -v tests.test_rpc_example and confirm all 16 tests pass across both PythonRpcExampleTest and NodeRpcExampleTest.
  2. Install either package into an isolated config directory with red plugin install --path ./examples/rpc-hello-plugin or red plugin install --path ./examples/rpc-hello-node-plugin, open a file containing multi-byte Unicode (such as const icon = "🦀";), and run :RpcHello world, :RpcDocument, :RpcApply // crab, :RpcUndo, and :RpcPanel / :RpcPanelClose.
  3. Run :RpcUndo a second time with no active transaction and confirm Red displays RpcApply has no transaction to undo as a warning while subsequent :RpcHello commands continue working.

@fcoury
fcoury merged commit 4a58fc6 into main Oct 14, 2026
16 checks passed
@fcoury
fcoury deleted the docs/rpc-plugin-examples branch October 14, 2026 21:28
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.

1 participant