Class: Solargraph::LanguageServer::Transport::DataReader
- Inherits:
-
Object
- Object
- Solargraph::LanguageServer::Transport::DataReader
- Defined in:
- lib/solargraph/language_server/transport/data_reader.rb
Instance Method Summary collapse
-
#initialize ⇒ DataReader
constructor
A new instance of DataReader.
-
#receive(data) ⇒ Object
Process raw data received from the client.
-
#set_message_handler {|The| ... } ⇒ Object
Declare a block to be executed for each message received from the client.
Constructor Details
#initialize ⇒ DataReader
Returns a new instance of DataReader.
9 10 11 12 13 |
# File 'lib/solargraph/language_server/transport/data_reader.rb', line 9 def initialize @in_header = true @content_length = 0 @buffer = String.new end |
Instance Method Details
#receive(data) ⇒ Object
Process raw data received from the client. The data will be parsed into messages based on the JSON-RPC protocol. Each message will be passed to the block declared via set_message_handler. Incomplete data will be buffered and subsequent data will be appended to the buffer.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/solargraph/language_server/transport/data_reader.rb', line 29 def receive data data.each_char do |char| @buffer.concat char if @in_header if @buffer.end_with?("\r\n\r\n") else if @buffer.bytesize == @content_length end end end |
#set_message_handler {|The| ... } ⇒ Object
Declare a block to be executed for each message received from the client.
19 20 21 |
# File 'lib/solargraph/language_server/transport/data_reader.rb', line 19 def &block @message_handler = block end |