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 6b5be71 commit 76911b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

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

# 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.
ActionDispatch::Routing::Mapper.route_source_locations = true

module RubyLsp
module Rails
Expand Down Expand Up @@ -161,7 +168,7 @@ def resolve_route_info(requirements)

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

Expand All @@ -188,9 +195,10 @@ def route_location(name)
{ error: e.full_message(highlight: false) }
end
else
def route_location(name)
{ result: nil }
end
raise "NOT ENABLED"
# def route_location(name)
# { result: 444 }
# end
end

def resolve_database_info_from_model(model_name)
Expand Down Expand Up @@ -254,4 +262,8 @@ def active_record_model?(const)
end
end

RubyLsp::Rails::Server.new.start if ARGV.first == "start"
if ARGV.first == "start"
ActionDispatch::Routing::Mapper.route_source_locations = true
RubyLsp::Rails::Server.new.start
ActionDispatch::Routing::Mapper.route_source_locations = true
end
1 change: 1 addition & 0 deletions test/ruby_lsp_rails/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ 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
end
Expand Down

0 comments on commit 76911b3

Please sign in to comment.