Class: RubyLsp::MessageWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/utils.rb

Overview

Writes JSON RPC messages to the given IO

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ MessageWriter

: (IO) -> void



328
329
330
# File 'lib/ruby_lsp/utils.rb', line 328

def initialize(io)
  @io = io
end

Instance Method Details

#write(message) ⇒ Object

: (Hash[Symbol, untyped]) -> void



333
334
335
336
337
338
339
# File 'lib/ruby_lsp/utils.rb', line 333

def write(message)
  message[:jsonrpc] = "2.0"
  json_message = message.to_json

  @io.write("Content-Length: #{json_message.bytesize}\r\n\r\n#{json_message}")
  @io.flush
end