# File lib/ruby_lsp/base_server.rb, line 114defnew_workerThread.newdowhile (message = T.let(@incoming_queue.pop, T.nilable(T::Hash[Symbol, T.untyped])))
id = message[:id]
# Check if the request was cancelled before trying to process it@mutex.synchronizedoifid&&@cancelled_requests.include?(id)
send_message(Result.new(id:id, response:nil))
@cancelled_requests.delete(id)
nextendendprocess_message(message)
endendend
pop_response()
# File lib/ruby_lsp/base_server.rb, line 103defpop_response@outgoing_queue.popend
process_message(message)
# File lib/ruby_lsp/base_server.rb, line 108defprocess_message(message); end
run_shutdown()
# File lib/ruby_lsp/base_server.rb, line 89defrun_shutdown@incoming_queue.clear@outgoing_queue.clear@incoming_queue.close@outgoing_queue.close@cancelled_requests.clear@worker.join@outgoing_dispatcher.join@store.clearend
send_empty_response(id)
# File lib/ruby_lsp/base_server.rb, line 145defsend_empty_response(id)
send_message(Result.new(id:id, response:nil))
end
send_message(message)
# File lib/ruby_lsp/base_server.rb, line 134defsend_message(message)
# When we're shutting down the server, there's a small race condition between closing the thread queues and# finishing remaining requests. We may close the queue in the middle of processing a request, which will then fail# when trying to send a response backreturnif@outgoing_queue.closed?@outgoing_queue<<message@current_request_id+=1ifmessage.is_a?(Request)
end
shutdown()
# File lib/ruby_lsp/base_server.rb, line 111defshutdown; end
start()
# File lib/ruby_lsp/base_server.rb, line 38defstart@reader.readdo|message|method = message[:method]
# We must parse the document under a mutex lock or else we might switch threads and accept text edits in the# source. Altering the source reference during parsing will put the parser in an invalid internal state, since# it started parsing with one source but then it changed in the middle. We don't want to do this for text# synchronization notifications@mutex.synchronizedouri = message.dig(:params, :textDocument, :uri)
ifuribeginparsed_uri = URI(uri)
message[:params][:textDocument][:uri] = parsed_uri# We don't want to try to parse documents on text synchronization notifications@store.get(parsed_uri).parseunlessmethod.start_with?("textDocument/did")
rescueErrno::ENOENT# If we receive a request for a file that no longer exists, we don't want to failendendend# The following requests need to be executed in the main thread directly to avoid concurrency issues. Everything# else is pushed into the incoming queuecasemethodwhen"initialize", "initialized", "textDocument/didOpen", "textDocument/didClose", "textDocument/didChange"process_message(message)
when"shutdown"$stderr.puts("Shutting down Ruby LSP...")
shutdown@mutex.synchronizedorun_shutdown@writer.write(Result.new(id:message[:id], response:nil).to_hash)
endwhen"exit"@mutex.synchronizedostatus = @incoming_queue.closed??0:1$stderr.puts("Shutdown complete with status #{status}")
exit(status)
endelse@incoming_queue<<messageendendend