Sha256: f0ec113653b005d799651d5521696724bc58705cce6e199e7e90c7e1ee7b49e7

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

module LanguageServer
  module Protocol
    module Stdio
      class Writer
        def respond(id:, result:)
          write(id: id, result: result)
        end

        def notify(method:, params: {})
          write(method: method, params: params)
        end

        private

        def write(response)
          response_str = response.merge(
            jsonrpc: "2.0"
          ).to_json

          headers = {
            "Content-Length" => response_str.bytesize
          }

          headers.each do |k, v|
            STDOUT.print "#{k}: #{v}\r\n"
          end

          STDOUT.print "\r\n"

          STDOUT.print response_str
          STDOUT.flush

          LanguageServer.logger.debug("Response: #{response_str}")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
language_server-0.4.0 lib/language_server/protocol/stdio/writer.rb
language_server-0.3.1 lib/language_server/protocol/stdio/writer.rb
language_server-0.3.0 lib/language_server/protocol/stdio/writer.rb