From 7d83ae89fbb45d4c6c6f374debac40cc162d47c0 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:01:10 -0400 Subject: [PATCH] wip --- lib/ruby_lsp/ruby_lsp_rails/server.rb | 26 +++++++------------------- test/ruby_lsp_rails/server_test.rb | 3 +-- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/server.rb b/lib/ruby_lsp/ruby_lsp_rails/server.rb index 593af2ed..418cc724 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/server.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/server.rb @@ -3,19 +3,12 @@ require "json" -# module ActionDispatch -# class MyRailtie < Rails::Railtie # :nodoc: -# initializer "my_railtie.configure", after: "action_dispatch.configure" do -# ActionDispatch::Routing::Mapper.route_source_locations = true -# end -# end -# end +ActionDispatch::Routing::Mapper.route_source_locations = true +Rails.application.routes.routes # 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. -# TODO: this helps but it still failing intermittently. Trying to understand what's going on. - module RubyLsp module Rails module Common @@ -168,7 +161,7 @@ def resolve_route_info(requirements) { result: body } else - { result: "SL NIL" } + { result: nil } end end @@ -195,10 +188,9 @@ def route_location(name) { error: e.full_message(highlight: false) } end else - raise "NOT ENABLED" - # def route_location(name) - # { result: 444 } - # end + def route_location(name) + { result: nil } + end end def resolve_database_info_from_model(model_name) @@ -262,8 +254,4 @@ def active_record_model?(const) end end -if ARGV.first == "start" - ActionDispatch::Routing::Mapper.route_source_locations = true - RubyLsp::Rails::Server.new.start - ActionDispatch::Routing::Mapper.route_source_locations = true -end +RubyLsp::Rails::Server.new.start if ARGV.first == "start" diff --git a/test/ruby_lsp_rails/server_test.rb b/test/ruby_lsp_rails/server_test.rb index 3a4da40a..e255a9b1 100644 --- a/test/ruby_lsp_rails/server_test.rb +++ b/test/ruby_lsp_rails/server_test.rb @@ -115,9 +115,8 @@ def <(other) test "route location returns the location for a valid route" do @server.execute("route_location", { name: "user_path" }) - puts response.inspect 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