Class: Rigor::LanguageServer::Loop
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::Loop
- Defined in:
- lib/rigor/language_server/loop.rb
Overview
JSON-RPC dispatch loop. Drains messages from ‘reader`, routes each to `server.dispatch`, and writes responses back through `writer`. Stops when either the reader hits EOF (client closed its end of the pipe) or the server transitions to `:exited`.
The Loop knows the request / notification distinction from the presence of the ‘id` field on the inbound JSON-RPC envelope:
-
Request (‘id` present) → ALWAYS gets a response (success or error). `Server#dispatch` returning nil for a request maps to `result: null` per the LSP shutdown contract.
-
Notification (‘id` absent) → NEVER gets a response. The dispatcher’s return value is discarded.
JSON parse errors at the framing boundary surface as an LSP ‘ParseError` (-32700) response with `id: null` per JSON-RPC spec § 5.1; the loop continues so a corrupt frame doesn’t poison the rest of the session.
Instance Method Summary collapse
-
#initialize(reader:, writer:, server:) ⇒ Loop
constructor
A new instance of Loop.
- #run ⇒ Object
Constructor Details
#initialize(reader:, writer:, server:) ⇒ Loop
Returns a new instance of Loop.
27 28 29 30 31 |
# File 'lib/rigor/language_server/loop.rb', line 27 def initialize(reader:, writer:, server:) @reader = reader @writer = writer @server = server end |
Instance Method Details
#run ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rigor/language_server/loop.rb', line 33 def run @reader.read do |request| handle(request) break if @server.exited? end rescue JSON::ParserError => e @writer.write(id: nil, error: { code: Server::ERROR_PARSE_ERROR, message: e. }) end |