Skip to content

Commit a0a95fc

Browse files
committed
Run reload in a background thread to keep the server responsive
On large Rails apps (e.g., Bourgeois), reload takes 10-20 seconds. During that time, the server can't process any other requests (model info, route info, associations), causing the editor to freeze. Run reload in a background thread and respond immediately. If another reload arrives while one is in progress, skip it — the running reload will pick up all file changes. This prevents N rapid saves from causing N sequential 20-second reloads. Trade-off: DSL generation may run against slightly stale state if it starts before reload finishes. This is mitigated by the "don't delete RBI" fix in Tapioca which preserves existing RBIs for missing constants. Related: Shopify/team-ruby-dx#1734
1 parent ca012cd commit a0a95fc

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,19 @@ def execute(request, params)
320320
send_result(run_migrations)
321321
end
322322
when "reload"
323-
with_progress("rails-reload", "Reloading Ruby LSP Rails instance") do
324-
begin
325-
::Rails.application.reloader.reload!
326-
send_result({ success: true })
327-
rescue StandardError => e
328-
log_message(
329-
"Request reload failed with #{e.class}:\n#{e.full_message(highlight: false)}",
330-
)
331-
send_result({ success: false })
323+
# Respond immediately so callers are not blocked while the app reloads.
324+
# Reload runs in a background thread to keep the server responsive to
325+
# other requests (model, route, association, etc.).
326+
# If a reload is already in progress, skip this one — the running reload
327+
# will pick up all file changes.
328+
if @reload_thread&.alive?
329+
send_result({ success: true, skipped: true })
330+
else
331+
send_result({ success: true })
332+
@reload_thread = Thread.new do
333+
with_notification_error_handling("reload") do
334+
::Rails.application.reloader.reload!
335+
end
332336
end
333337
end
334338
when "route_location"

0 commit comments

Comments
 (0)