Class: Rfmt::LSP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rfmt/lsp/server.rb

Constant Summary collapse

TEXT_DOCUMENT_SYNC_FULL =
1
METHOD_NOT_FOUND =
-32_601
INTERNAL_ERROR =
-32_603

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout) ⇒ Server

Returns a new instance of Server.



19
20
21
22
23
24
# File 'lib/rfmt/lsp/server.rb', line 19

def initialize(input: $stdin, output: $stdout)
  @io = MessageIO.new(input: input, output: output)
  @documents = DocumentStore.new
  @workspace = Workspace.new
  @shutdown_requested = false
end

Instance Method Details

#handle_message(message) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rfmt/lsp/server.rb', line 34

def handle_message(message)
  method = message['method']
  id = message['id']
  params = message['params'] || {}

  dispatch_message(method, id, params)
rescue StandardError => e
  respond_error(id, INTERNAL_ERROR, e.message) if id
end

#runObject



26
27
28
29
30
31
32
# File 'lib/rfmt/lsp/server.rb', line 26

def run
  while (message = @io.read_message)
    return @shutdown_requested ? 0 : 1 if handle_message(message) == :exit
  end

  0
end