Sha256: df027607fea9ebc21b5606a485c3f3ce6f96a89ae5ed1fe4716c8144b2048e42

Contents?: true

Size: 1.73 KB

Versions: 107

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require 'language_server-protocol'
require_relative 'logger'
require_relative 'routes'
require_relative 'runtime'

#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
#
module RuboCop
  module Lsp
    # Language Server Protocol of RuboCop.
    # @api private
    class Server
      def initialize(config_store)
        @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

      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

      def write(response)
        @writer.write(response)
      end

      def format(path, text, command:)
        @runtime.format(path, text, command: command)
      end

      def offenses(path, text)
        @runtime.offenses(path, text)
      end

      def configure(options)
        @runtime.safe_autocorrect = options[:safe_autocorrect]
        @runtime.lint_mode = options[:lint_mode]
        @runtime.layout_mode = options[:layout_mode]
      end

      def stop(&block)
        at_exit(&block) if block
        exit
      end
    end
  end
end

Version data entries

107 entries across 107 versions & 8 rubygems

Version Path
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/lsp/server.rb
rubocop-1.60.2 lib/rubocop/lsp/server.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
rubocop-1.60.1 lib/rubocop/lsp/server.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/lsp/server.rb
rubocop-1.60.0 lib/rubocop/lsp/server.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/lsp/server.rb