Skip to content

Commit a4af8b3

Browse files
committed
Reuse the same executor instead of creating a new one per request
1 parent d946616 commit a4af8b3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/ruby_lsp/server.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def initialize
2727
# The messages queue includes requests and notifications to be sent to the client
2828
@message_queue = T.let(Thread::Queue.new, Thread::Queue)
2929

30+
# The executor is responsible for executing requests
31+
@executor = T.let(Executor.new(@store, @message_queue), Executor)
32+
3033
# Create a thread to watch the messages queue and send them to the client
3134
@message_dispatcher = T.let(
3235
Thread.new do
@@ -62,7 +65,7 @@ def start
6265
@reader.read do |request|
6366
case request[:method]
6467
when "initialize", "initialized", "textDocument/didOpen", "textDocument/didClose", "textDocument/didChange"
65-
result = Executor.new(@store, @message_queue).execute(request)
68+
result = @executor.execute(request)
6669
finalize_request(result, request)
6770
when "$/cancelRequest"
6871
# Cancel the job if it's still in the queue
@@ -126,7 +129,7 @@ def new_worker
126129
# We need to return nil to the client even if the request was cancelled
127130
Result.new(response: nil)
128131
else
129-
Executor.new(@store, @message_queue).execute(request)
132+
@executor.execute(request)
130133
end
131134

132135
finalize_request(result, request)

0 commit comments

Comments
 (0)