Fix LSP client on Windows: stream reading and server request handling#4
Open
ronti1 wants to merge 1 commit intoHYMMA:masterfrom
Open
Fix LSP client on Windows: stream reading and server request handling#4ronti1 wants to merge 1 commit intoHYMMA:masterfrom
ronti1 wants to merge 1 commit intoHYMMA:masterfrom
Conversation
The LSP client's ProcessMessage treated all messages with an 'id' field
as responses to client requests. However, LSP servers also send requests
TO the client (e.g. client/registerCapability, workspace/configuration)
which have both 'id' AND 'method' fields. These were silently dropped,
causing the server to block waiting for a response and never process
subsequent client requests like textDocument/documentSymbol.
Changes:
- Distinguish server-sent requests (id+method) from responses (id only)
and notifications (method only) in ProcessMessage
- Add SendServerResponseAsync to reply with {result:null} to server
requests, using manual JSON to avoid WhenWritingNull stripping the
result field
- Use StreamReader for header reading (ReadLineAsync) instead of
byte-by-byte BaseStream reading, matching the previous ReadLoopAsync
fix
- Add debug logging for notifications and unknown response IDs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix LSP client on Windows: stream reading and server request handling
Problem
The LSP client fails on Windows with two issues:
Stream reading hangs:
ReadContentLengthAsyncreads fromProcess.StandardOutput.BaseStreambyte-by-byte, which silently fails on Windows pipes. The .NETProcessclass wraps stdout in aStreamReaderwith internal buffering — reading the underlyingBaseStreambypasses this buffer, causingReadAsyncto never receive data even thoughcsharp-lswrites correctly.Server requests dropped:
ProcessMessagetreats all messages with anidfield as responses to client requests. However,csharp-lssends server-to-client requests (e.g.,client/registerCapability,workspace/configuration) that have bothidandmethodfields. These are silently dropped, causingcsharp-lsto block waiting for responses and never process subsequent requests.Fix
Stream reading — replaced
BaseStreambyte-by-byte reading withStreamReader.ReadLineAsync()for headers andStreamReader.ReadAsync(Memory<char>)for body content. SetStandardOutputEncoding = new UTF8Encoding(false)to ensure consistent encoding.Server requests — updated
ProcessMessageto distinguish three JSON-RPC message types:id+method→ server request → auto-respond with{result: null}idonly → client response → dispatch to pending TCSmethodonly → notification → handle/logAdded
SendServerResponseAsyncthat builds JSON manually to avoidWhenWritingNullstripping theresult: nullfield.Testing
Verified on Windows with
csharp-ls0.22.0 (.NET 10):set_workspace→ loads solution successfullycsharp_symbols→ returns document symbolscsharp_hover,csharp_definition,csharp_references→ all working