Class: Spoom::LSP::Message

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/sorbet/lsp/base.rb

Overview

A general message as defined by JSON-RPC.

The language server protocol always uses ‘“2.0”` as the `jsonrpc` version.

Direct Known Subclasses

Notification, Request

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



16
17
18
# File 'lib/spoom/sorbet/lsp/base.rb', line 16

def initialize
  @jsonrpc = T.let("2.0", String)
end

Instance Method Details

#as_jsonObject



21
22
23
24
25
26
# File 'lib/spoom/sorbet/lsp/base.rb', line 21

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

#to_json(*args) ⇒ Object



29
30
31
# File 'lib/spoom/sorbet/lsp/base.rb', line 29

def to_json(*args)
  T.unsafe(as_json).to_json(*args)
end