monaco-languageclient icon indicating copy to clipboard operation
monaco-languageclient copied to clipboard

Is there anyway to use server actions to provide language client connections?

Open alissa-tung opened this issue 1 year ago • 0 comments

In recent versions of React allowed some functions to run on server side runtime (for example, node), and pass the result of calling such functions to client side runtime (browser)

A common language server program can be called by using NodeJS child_process spawn, where the return value of such spawn have two properties stdin and stdout.

stdin and stdout can be turns in to StreamMessageReader and StreamMessageWriter from vscode-jsonrpc/node, the pair of them is MessageTransport

the key of Message reader and writer is the read and write function, that is, consider the following case

  • listen: can be called only once, started listen to following messages, takes a callback as argument: listen : (JSON -> void) -> Disposable
  • write: JSON -> Promise

if we had already created StreamMessageReader and StreamMessageWriter on server side, export the write and read function as async server actions, then in the client side we declare two new class, use the exported server actions to define the methods

class ServerStreamMessageReader
  extends rpc.AbstractMessageReader
  implements rpc.MessageReader
{
  listen(callback: rpc.DataCallback): rpc.Disposable {

and

class ServerStreamMessageWriter
  extends rpc.AbstractMessageWriter
  implements rpc.MessageWriter
{
  write(msg: rpc.Message): Promise<void> {

but directly wrap the server actions is not okay, since server actions can not have a client function as argument.

So can we use a API which is not like listen (which takes a callback) , or can we have some methods to fix the server actions?

alissa-tung avatar Feb 15 '24 06:02 alissa-tung