0

我正在使用csharp-language-server-protocol实现来创建自定义语言服务器,并且效果很好(请参阅LSP)。

唯一的问题是我没有找到一种很好的方法来使用 .Net将服务器使用的输入/输出流连接到websocket(我希望它作为远程语言服务器工作,以便我可以使用 web sockets 连接到它)。

我已经完成了自己的连接器,并且可以正常工作:

  • 它从网络套接字获取消息并将它们写入输入流
  • 它从输出流中读取消息并通过 Web 套接字发送它们

但我确信一定有一个我无法找到的现有解决方案。

我尝试使用vs-streamjsonrpc,但我认为这不是我需要的。

我也尝试过使用Nerdbank.Streams#AsStream,但没有成功(见下面的例外):

(...)
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)

有人有例子吗?有什么提示吗?

4

0 回答 0