Sha256: c937b8fa604cd7d6c44a49482ed8cdac54791e4348c9c2950aa9d78b9ee12cec

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

# typed: strict
# frozen_string_literal: true

module Spoom
  module LSP
    # Base messaging
    # We don't use T::Struct for those so we can subclass them

    # A general message as defined by JSON-RPC.
    #
    # The language server protocol always uses `"2.0"` as the `jsonrpc` version.
    class Message
      extend T::Sig

      sig { void }
      def initialize
        @jsonrpc = T.let("2.0", String)
      end

      sig { returns(T::Hash[T.untyped, T.untyped]) }
      def as_json
        instance_variables.each_with_object({}) do |var, obj|
          val = instance_variable_get(var)
          obj[var.to_s.delete("@")] = val if val
        end
      end

      sig { params(args: T.untyped).returns(String) }
      def to_json(*args)
        T.unsafe(as_json).to_json(*args)
      end
    end

    # A request message to describe a request between the client and the server.
    #
    # Every processed request must send a response back to the sender of the request.
    class Request < Message
      extend T::Sig

      sig { returns(Integer) }
      attr_reader :id

      sig { returns(T::Hash[T.untyped, T.untyped]) }
      attr_reader :params

      sig { params(id: Integer, method: String, params: T::Hash[T.untyped, T.untyped]).void }
      def initialize(id, method, params)
        super()
        @id = id
        @method = method
        @params = params
      end
    end

    # A notification message.
    #
    # A processed notification message must not send a response back. They work like events.
    class Notification < Message
      extend T::Sig

      sig { returns(String) }
      attr_reader :method

      sig { returns(T::Hash[T.untyped, T.untyped]) }
      attr_reader :params

      sig { params(method: String, params: T::Hash[T.untyped, T.untyped]).void }
      def initialize(method, params)
        super()
        @method = method
        @params = params
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spoom-1.5.2 lib/spoom/sorbet/lsp/base.rb
spoom-1.5.1 lib/spoom/sorbet/lsp/base.rb
spoom-1.5.0 lib/spoom/sorbet/lsp/base.rb
spoom-1.4.2 lib/spoom/sorbet/lsp/base.rb
spoom-1.4.1 lib/spoom/sorbet/lsp/base.rb
spoom-1.4.0 lib/spoom/sorbet/lsp/base.rb
spoom-1.3.3 lib/spoom/sorbet/lsp/base.rb
spoom-1.3.2 lib/spoom/sorbet/lsp/base.rb
spoom-1.3.1 lib/spoom/sorbet/lsp/base.rb
spoom-1.3.0 lib/spoom/sorbet/lsp/base.rb
spoom-1.2.4 lib/spoom/sorbet/lsp/base.rb
spoom-1.2.3 lib/spoom/sorbet/lsp/base.rb
spoom-1.2.2 lib/spoom/sorbet/lsp/base.rb