Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 28, 2024
1 parent 76911b3 commit 7d83ae8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
26 changes: 7 additions & 19 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -168,7 +161,7 @@ def resolve_route_info(requirements)

{ result: body }
else
{ result: "SL NIL" }
{ result: nil }
end
end

Expand All @@ -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)
Expand Down Expand Up @@ -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"
3 changes: 1 addition & 2 deletions test/ruby_lsp_rails/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d83ae8

Please sign in to comment.