Class: RubyLsp::Executor

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

Overview

This class dispatches a request execution to the right request class. No IO should happen anywhere here!

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Executor

Returns a new instance of Executor.



10
11
12
13
14
15
# File 'lib/ruby_lsp/executor.rb', line 10

def initialize(store)
  # Requests that mutate the store must be run sequentially! Parallel requests only receive a temporary copy of the
  # store
  @store = store
  @notifications = T.let([], T::Array[Notification])
end

Instance Method Details

#execute(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_lsp/executor.rb', line 18

def execute(request)
  response = T.let(nil, T.untyped)
  error = T.let(nil, T.nilable(Exception))

  request_time = Benchmark.realtime do
    response = run(request)
  rescue StandardError, LoadError => e
    error = e
  end

  Result.new(response: response, error: error, request_time: request_time, notifications: @notifications)
end