I am using the csharp-language-server-protocol implementation to create a custom language server and it works great (see LSP).
The only problem is that I am not finding a nice way to connect the in/out streams the server uses to a websocket using .Net (I want it to work as a remote language server so I can connect to it using web sockets).
I have done my own connector and it works:
- it gets the messages from the web socket and writes them into the input stream
- it reads the messages from the output stream and sends them through the web socket
But I am sure there must be an existing solution that I am not managing to find.
I tried with vs-streamjsonrpc but I don't think that's what I need.
I also tried with Nerdbank.Streams#AsStream with no luck (see exception below):
(...)
var websocket = await context.WebSockets.AcceptWebSocketAsync();
var inOutStream = webSocket.AsStream();
var languageServer = await LanguageServer.From(options => options
.WithInput(inOutStream)
.WithOutput(inOutStream)
...
System.ArgumentException: 'Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.'
This exception was originally thrown at this call stack:
System.ThrowHelper.ThrowArraySegmentCtorValidationFailedExceptions(System.Array, int, int)
Nerdbank.Streams.WebSocketStream.ReadAsync(byte[], int, int, System.Threading.CancellationToken)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
Nerdbank.Streams.WebSocketStream.Read(byte[], int, int)
OmniSharp.Extensions.JsonRpc.InputHandler.ProcessInputStream()
System.Threading.ThreadHelper.ThreadStart_Context(object)
Does anyone have an example? Any hints?