diff --git a/lib/ruby_lsp/ruby_lsp_rails/server.rb b/lib/ruby_lsp/ruby_lsp_rails/server.rb index 7cad461c..cbe0cca9 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/server.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/server.rb @@ -3,6 +3,12 @@ require "json" +if ActionDispatch::Routing::Mapper.respond_to?(:route_source_locations) + ActionDispatch::Routing::Mapper.route_source_locations = true +end + +Rails.application.routes.eager_load! + # NOTE: We should avoid printing to stderr since it causes problems. We never read the standard error pipe from the # client, so it will become full and eventually hang or crash. Instead, return a response with an `error` key. diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 9d61df68..fa61c344 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_05_21_183200) do +ActiveRecord::Schema[8.0].define(version: 2024_10_25_225348) do create_table "composite_primary_keys", primary_key: ["order_id", "product_id"], force: :cascade do |t| t.integer "order_id" t.integer "product_id" diff --git a/test/ruby_lsp_rails/server_test.rb b/test/ruby_lsp_rails/server_test.rb index 1b3f68ce..e255a9b1 100644 --- a/test/ruby_lsp_rails/server_test.rb +++ b/test/ruby_lsp_rails/server_test.rb @@ -116,7 +116,7 @@ def <(other) test "route location returns the location for a valid route" do @server.execute("route_location", { name: "user_path" }) location = response[:result][:location] - assert_match %r{test/dummy/config/routes.rb:4$}, location + assert_match %r{test/dummy/config/routes.rb:3$}, location end test "route location returns nil for invalid routes" do @@ -130,7 +130,7 @@ def <(other) result = response[:result] source_location_path, source_location_line = result[:source_location] - assert_equal "4", source_location_line + assert_equal "3", source_location_line assert source_location_path.end_with?("config/routes.rb") assert_equal "GET", result[:verb] assert_equal "/users(.:format)", result[:path]