Skip to content

Commit

Permalink
Fixes for Rails 8
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 30, 2024
1 parent ad5f781 commit 4eb2491
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/ruby_lsp_rails/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 4eb2491

Please sign in to comment.