Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def start

request = JSON.parse(json, symbolize_names: true)
execute(request.fetch(:method), request[:params])
disconnect_from_database
end
end

Expand Down Expand Up @@ -493,6 +494,18 @@ def clear_file_system_resolver_hooks
end
end

# Keeping a connection to the database prevents it from being dropped in development. We don't actually need to
# to reuse database connections for the LSP server, the performance benefit of doing so only matters in production
# where there is latency, locally we're fine with the small overhead of establishing a new connection on each request.
#: -> void
def disconnect_from_database
return unless defined?(::ActiveRecord::Base)

with_notification_error_handling("disconnect_from_database") do
ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
end
end

#: (singleton(ActiveRecord::Base)) -> Array[String]
def collect_model_foreign_keys(model)
return [] unless model.connection.respond_to?(:supports_foreign_keys?) &&
Expand Down
Loading