Class: Solargraph::LanguageServer::Message::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/language_server/message/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, request) ⇒ Base

Returns a new instance of Base.

Parameters:



30
31
32
33
34
35
36
37
# 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

Instance Attribute Details

#errorHash? (readonly)

Returns:

  • (Hash, nil)


26
27
28
# File 'lib/solargraph/language_server/message/base.rb', line 26

def error
  @error
end

#hostSolargraph::LanguageServer::Host (readonly)



8
9
10
# File 'lib/solargraph/language_server/message/base.rb', line 8

def host
  @host
end

#idInteger (readonly)

Returns:

  • (Integer)


11
12
13
# File 'lib/solargraph/language_server/message/base.rb', line 11

def id
  @id
end

#methodString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/solargraph/language_server/message/base.rb', line 17

def method
  @method
end

#paramsHash (readonly)

Returns:

  • (Hash)


20
21
22
# File 'lib/solargraph/language_server/message/base.rb', line 20

def params
  @params
end

#requestHash (readonly)

Returns:

  • (Hash)


14
15
16
# File 'lib/solargraph/language_server/message/base.rb', line 14

def request
  @request
end

#resultHash, ... (readonly)

Returns:

  • (Hash, Array, nil)


23
24
25
# File 'lib/solargraph/language_server/message/base.rb', line 23

def result
  @result
end

Instance Method Details

#post_initializevoid

This method returns an undefined value.



40
# File 'lib/solargraph/language_server/message/base.rb', line 40

def post_initialize; end

#processvoid

This method returns an undefined value.



43
# File 'lib/solargraph/language_server/message/base.rb', line 43

def process; end

#send_responsevoid

This method returns an undefined value.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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) ⇒ void

This method returns an undefined value.

Parameters:

  • code (Integer)

    See Solargraph::LanguageServer::ErrorCodes

  • message (String)


54
55
56
57
58
59
# File 'lib/solargraph/language_server/message/base.rb', line 54

def set_error code, message
  @error = {
    code: code,
    message: message
  }
end

#set_result(data) ⇒ void

This method returns an undefined value.

Parameters:

  • data (Hash, Array, nil)


47
48
49
# File 'lib/solargraph/language_server/message/base.rb', line 47

def set_result data
  @result = data
end