# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 14defcreate_clientifFile.exist?("bin/rails")
newelse$stderr.puts(<<~MSG)
Ruby LSP Rails failed to locate bin/rails in the current directory: #{Dir.pwd}"
MSG$stderr.puts("Server dependent features will not be available")
NullClient.newendrescueErrno::ENOENT, StandardError=>e# rubocop:disable Lint/ShadowedException$stderr.puts("Ruby LSP Rails failed to initialize server: #{e.message}\n#{e.backtrace&.join("\n")}")
$stderr.puts("Server dependent features will not be available")
NullClient.newend
new()
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 40definitialize# Spring needs a Process session ID. It uses this ID to "attach" itself to the parent process, so that when the# parent ends, the spring process ends as well. If this is not set, Spring will throw an error while trying to# set its own session IDbeginProcess.setpgrpProcess.setsidrescueErrno::EPERM# If we can't set the session ID, continuerescueNotImplementedError# setpgrp() may be unimplemented on some platform# https://github.com/Shopify/ruby-lsp-rails/issues/348endstdin, stdout, stderr, wait_thread = Bundler.with_original_envdoOpen3.popen3("bundle", "exec", "rails", "runner", "#{__dir__}/server.rb", "start")
end@stdin = T.let(stdin, IO)
@stdout = T.let(stdout, IO)
@stderr = T.let(stderr, IO)
@wait_thread = T.let(wait_thread, Process::Waiter)
@stdin.binmode# for Windows compatibility@stdout.binmode# for Windows compatibility$stderr.puts("Ruby LSP Rails booting server")
count = 0begincount+=1read_responserescueEmptyMessageError$stderr.puts("Ruby LSP Rails is retrying initialize (#{count})")
retryifcount<MAX_RETRIESend$stderr.puts("Finished booting Ruby LSP Rails server")
unlessENV["RAILS_ENV"] =="test"at_exitdoif@wait_thread.alive?$stderr.puts("Ruby LSP Rails is force killing the server")
sleep(0.5) # give the server a bit of time if we already issued a shutdown notification# Windows does not support the `TERM` signal, so we're forced to use `KILL` hereProcess.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
endendendrescueErrno::EPIPE, IncompleteMessageErrorraiseInitializationError, @stderr.readend
Public Instance Methods
model(name)
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 94defmodel(name)
make_request("model", name:name)
rescueIncompleteMessageError$stderr.puts("Ruby LSP Rails failed to get model information: #{@stderr.read}")
nilend
route_location(name)
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 102defroute_location(name)
make_request("route_location", name:name)
rescueIncompleteMessageError$stderr.puts("Ruby LSP Rails failed to get route location: #{@stderr.read}")
nilend
shutdown()
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 119defshutdown$stderr.puts("Ruby LSP Rails shutting down server")
send_message("shutdown")
sleep(0.5) # give the server a bit of time to shutdown
[@stdin, @stdout, @stderr].each(&:close)
end
stopped?()
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 127defstopped?
[@stdin, @stdout, @stderr].all?(&:closed?) &&!@wait_thread.alive?end
trigger_reload()
# File lib/ruby_lsp/ruby_lsp_rails/runner_client.rb, line 110deftrigger_reload$stderr.puts("Reloading Rails application")
send_notification("reload")
rescueIncompleteMessageError$stderr.puts("Ruby LSP Rails failed to trigger reload")
nilend