Skip to content

Commit 0e1b659

Browse files
committed
Don't generate app_uri.txt if the ruby_lsp_rails.server is false
Because the addon client uses the file's existence to determine whether to send the request, if the file is generated when the server feature is disabled, the client would just spam the server with requests. We also don't need to append the Rack app if Rails server is not invoked.
1 parent 3347ca7 commit 0e1b659

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/ruby_lsp_rails/railtie.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ class Railtie < ::Rails::Railtie
1212

1313
initializer "ruby_lsp_rails.setup" do |_app|
1414
config.after_initialize do |app|
15-
unless config.ruby_lsp_rails.server == false
15+
# If we start the app with `bin/rails console` then `Rails::Server` is not defined.
16+
if defined?(::Rails::Server) && config.ruby_lsp_rails.server
1617
app.routes.prepend do
1718
T.bind(self, ActionDispatch::Routing::Mapper)
1819
mount(RackApp.new => RackApp::BASE_PATH)
1920
end
20-
end
2121

22-
# If we start the app with `bin/rails console` then `Rails::Server` is not defined.
23-
if defined?(::Rails::Server)
2422
ssl_enable, host, port = ::Rails::Server::Options.new.parse!(ARGV).values_at(:SSLEnable, :Host, :Port)
2523
app_uri = "#{ssl_enable ? "https" : "http"}://#{host}:#{port}"
2624
app_uri_path = ::Rails.root.join("tmp", "app_uri.txt")

0 commit comments

Comments
 (0)