class RuboCop::LSP::Server

Language Server Protocol of RuboCop. @api private

Public Class Methods

new(config_store) click to toggle source
# File lib/rubocop/lsp/server.rb, line 22
def initialize(config_store)
  $PROGRAM_NAME = "rubocop --lsp #{ConfigFinder.project_root}"

  RuboCop::LSP.enable

  @reader = LanguageServer::Protocol::Transport::Io::Reader.new($stdin)
  @writer = LanguageServer::Protocol::Transport::Io::Writer.new($stdout)
  @runtime = RuboCop::LSP::Runtime.new(config_store)
  @routes = Routes.new(self)
end

Public Instance Methods

configure(options) click to toggle source
# File lib/rubocop/lsp/server.rb, line 60
def configure(options)
  @runtime.safe_autocorrect = options[:safe_autocorrect]
  @runtime.lint_mode = options[:lint_mode]
  @runtime.layout_mode = options[:layout_mode]
end
format(path, text, command:) click to toggle source
# File lib/rubocop/lsp/server.rb, line 52
def format(path, text, command:)
  @runtime.format(path, text, command: command)
end
offenses(path, text) click to toggle source
# File lib/rubocop/lsp/server.rb, line 56
def offenses(path, text)
  @runtime.offenses(path, text)
end
start() click to toggle source
# File lib/rubocop/lsp/server.rb, line 33
def start
  @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 StandardError => e
    Logger.log("Error #{e.class} #{e.message[0..100]}")
    Logger.log(e.backtrace.inspect)
  end
end
stop(&block) click to toggle source
# File lib/rubocop/lsp/server.rb, line 66
def stop(&block)
  at_exit(&block) if block
  exit
end
write(response) click to toggle source
# File lib/rubocop/lsp/server.rb, line 48
def write(response)
  @writer.write(response)
end