Sha256: 450786893158445c1ca6cbe10b1faf0b90d3d5ddb4cd9e54de5363f688c104b8

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

# typed: true
# 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
      attr_reader :jsonrpc

      def initialize
        @jsonrpc = '2.0'
      end

      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

      def to_json(*args)
        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
      attr_reader :id, :method, :params

      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
      attr_reader :method, :params

      def initialize(method, params)
        super()
        @method = method
        @params = params
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spoom-1.1.8 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.7 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.6 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.5 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.4 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.3 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.2 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.1 lib/spoom/sorbet/lsp/base.rb
spoom-1.1.0 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.9 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.8 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.7 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.6 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.5 lib/spoom/sorbet/lsp/base.rb
spoom-1.0.4 lib/spoom/sorbet/lsp/base.rb