Skip to content

Commit 6af704a

Browse files
authored
Eager load routes (fixes failing test) (#499)
* Ensure routes are loaded * Only run reload_routes_unless_loaded for Rails 8
1 parent 77650f0 commit 6af704a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ def resolve_route_info(requirements)
167167
if ActionDispatch::Routing::Mapper.respond_to?(:route_source_locations) &&
168168
ActionDispatch::Routing::Mapper.route_source_locations
169169
def route_location(name)
170+
# In Rails 8, Rails.application.routes.named_routes is not populated by default
171+
if ::Rails.application.respond_to?(:reload_routes_unless_loaded)
172+
::Rails.application.reload_routes_unless_loaded
173+
end
174+
170175
match_data = name.match(/^(.+)(_path|_url)$/)
171176
return { result: nil } unless match_data
172177

0 commit comments

Comments
 (0)