elisp-json-rpc
elisp-json-rpc copied to clipboard
Support for IPC via STDIO using JSON-RPC
Based on the README, you need a host and port to do json-rpc in elisp. There are many programs which use STDIO for communication (LSP servers, for example). I'm working on a pull request for this. Is it okay to add STDIO support to this library?
I'm not opposed to this so long as it doesn't interfere with the current functionality. Though I wonder how you plan to pull it off, since access to stdin and stdout from Emacs Lisp is, unfortunately, very limited.
A typical approach would be to use HTTP-like framing, like the language server protocol (https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#base-protocol).
From Emacs you'd start an asynchronous process with make-process
. It needs a custom process filter. The filter would insert the new stdout into a temporary buffer and check for completed responses (i.e. where there's enough JSON content to read). Completed responses would be dispatched according to their IDs and removed from the temporary buffer.
Yes, I also want to communicate clangd
via stdio/stdout interface.
You can see an example of this kind of implementation in jorgenschaefer/elpy, although as it notes at the top, it uses a limited JSON-RPC implementation itself.