Class: RubyLsp::Handler

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/handler.rb

Defined Under Namespace

Classes: RequestHandler

Constant Summary collapse

VOID =
T.let(Object.new.freeze, Object)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



52
53
54
55
56
57
58
# File 'lib/ruby_lsp/handler.rb', line 52

def initialize
  @writer = T.let(Transport::Stdio::Writer.new, Transport::Stdio::Writer)
  @reader = T.let(Transport::Stdio::Reader.new, Transport::Stdio::Reader)
  @handlers = T.let({}, T::Hash[String, RequestHandler])
  @store = T.let(Store.new, Store)
  @queue = T.let(Queue.new(@writer, @handlers), Queue)
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



49
50
51
# File 'lib/ruby_lsp/handler.rb', line 49

def store
  @store
end

Class Method Details

.start(&blk) ⇒ Object



41
42
43
44
45
# File 'lib/ruby_lsp/handler.rb', line 41

def start(&blk)
  handler = new
  handler.instance_exec(&blk)
  handler.start
end

Instance Method Details

#startObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ruby_lsp/handler.rb', line 61

def start
  $stderr.puts "Starting Ruby LSP..."

  @reader.read do |request|
    handler = @handlers[request[:method]]
    next if handler.nil?

    if handler.parallel
      @queue.push(request)
    else
      result = @queue.execute(request)
      @queue.finalize_request(result, request)
    end
  end
end