Class: Standard::Lsp::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
# File 'lib/standard/lsp/server.rb', line 12

def initialize(config)
  @writer = Proto::Transport::Io::Writer.new($stdout)
  @reader = Proto::Transport::Io::Reader.new($stdin)
  @logger = Logger.new
  @standardizer = Standard::Lsp::Standardizer.new(config)
  @routes = Routes.new(@writer, @logger, @standardizer)
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/standard/lsp/server.rb', line 20

def start
  RuboCop::LSP.enable
  @reader.read do |request|
    if !request.key?(:method)
      @routes.handle_method_missing(request)
    elsif (route = @routes.for(request[:method]))
      route.call(request)
    else
      @routes.handle_unsupported_method(request)
    end
  rescue => e
    @logger.puts "Error #{e.class} #{e.message[0..100]}"
    @logger.puts e.backtrace.inspect
  end
end