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:


28
29
30
31
32
33
34
35
# File 'lib/solargraph/language_server/message/base.rb', line 28

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)

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

def error
  @error
end

#hostSolargraph::LanguageServer::Host (readonly)


6
7
8
# File 'lib/solargraph/language_server/message/base.rb', line 6

def host
  @host
end

#idInteger (readonly)

Returns:

  • (Integer)

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

def id
  @id
end

#methodString (readonly)

Returns:

  • (String)

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

def method
  @method
end

#paramsHash (readonly)

Returns:

  • (Hash)

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

def params
  @params
end

#requestHash (readonly)

Returns:

  • (Hash)

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

def request
  @request
end

#resultHash, ... (readonly)

Returns:

  • (Hash, Array, nil)

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

def result
  @result
end

Instance Method Details

#post_initializevoid

This method returns an undefined value.


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

def post_initialize; end

#processvoid

This method returns an undefined value.


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

def process; end

#send_responsevoid

This method returns an undefined value.


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/solargraph/language_server/message/base.rb', line 60

def send_response
  return if id.nil?
  if host.cancel?(id)
    Solargraph::Logging.logger.info "Cancelled response to #{method}"
    return
  end
  Solargraph::Logging.logger.info "Sending response to #{method}"
  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)

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

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)

45
46
47
# File 'lib/solargraph/language_server/message/base.rb', line 45

def set_result data
  @result = data
end