class Solargraph::LanguageServer::Message::Base

Attributes

error[R]

@return [Hash, nil]

host[R]

@return [Solargraph::LanguageServer::Host]

id[R]

@return [Integer]

method[R]

@return [String]

params[R]

@return [Hash]

request[R]

@return [Hash]

result[R]

@return [Hash, Array, nil]

Public Class Methods

new(host, request) click to toggle source

@param host [Solargraph::LanguageServer::Host] @param request [Hash]

# File lib/solargraph/language_server/message/base.rb, line 30
def initialize host, request
  @host = host
  @id = request['id'].freeze
  @request = request.freeze
  @method = request['method'].freeze
  @params = (request['params'] || {}).freeze
  post_initialize
end

Public Instance Methods

post_initialize() click to toggle source

@return [void]

# File lib/solargraph/language_server/message/base.rb, line 40
def post_initialize; end
process() click to toggle source

@return [void]

# File lib/solargraph/language_server/message/base.rb, line 43
def process; end
send_response() click to toggle source

@return [void]

# File lib/solargraph/language_server/message/base.rb, line 62
def send_response
  return if id.nil?
  if host.cancel?(id)
    # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest
    # cancel should send response RequestCancelled
    Solargraph::Logging.logger.info "Cancelled response to #{method}"
    set_result nil
    set_error ErrorCodes::REQUEST_CANCELLED, "cancelled by client"
  else
    Solargraph::Logging.logger.info "Sending response to #{method}"
  end
  response = {
    jsonrpc: "2.0",
    id: id,
  }
  response[:result] = result unless result.nil?
  response[:error] = error unless error.nil?
  response[:result] = nil if result.nil? and error.nil?
  json = response.to_json
  envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
  Solargraph.logger.debug envelope
  host.queue envelope
  host.clear id
end
set_error(code, message) click to toggle source

@param code [Integer] See Solargraph::LanguageServer::ErrorCodes @param message [String] @return [void]

# File lib/solargraph/language_server/message/base.rb, line 54
def set_error code, message
  @error = {
    code: code,
    message: message
  }
end
set_result(data) click to toggle source

@param data [Hash, Array, nil] @return [void]

# File lib/solargraph/language_server/message/base.rb, line 47
def set_result data
  @result = data
end