Class: TypeProf::LSP::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/lsp/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Writer

Returns a new instance of Writer.



314
315
316
317
# File 'lib/typeprof/lsp/server.rb', line 314

def initialize(io)
  @io = io
  @mutex = Mutex.new
end

Instance Method Details

#write(**json) ⇒ Object



319
320
321
322
323
324
325
# File 'lib/typeprof/lsp/server.rb', line 319

def write(**json)
  json = JSON.generate(json.merge(jsonrpc: "2.0"))
  @mutex.synchronize do
    @io << "Content-Length: #{ json.bytesize }\r\n\r\n" << json
    @io.flush
  end
end