Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Apr 25, 2024
1 parent 23620ab commit a9f2360
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/ruby_lsp/ruby_lsp_rails/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Rails
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_definition) jumps to the
# definition of the symbol under the cursor.
#
# It is available only Rails 7.1 or newer.
#
# Currently supported targets:
# - Callbacks
# - Named routes (e.g. `users_path`)
Expand All @@ -22,6 +20,7 @@ module Rails
# ```
#
# Notes for named routes:
# - It is available only in Rails 7.1 or newer.
# - Route may be defined across multiple files, e.g. using `draw`, rather than in `routes.rb`.
# - Routes won't be found if not defined for the Rails development environment.
# - If using `constraints`, the route can only be found if the constraints are met.
Expand Down Expand Up @@ -58,7 +57,7 @@ def on_call_node_enter(node)

if Support::Callbacks::ALL.include?(message)
handle_callback(node)
elsif message.match?(/^([a-zA-Z0-9_]+)(_path|_url)$/)
elsif message.end_with?("_path") || message.end_with?("_url")
handle_route(node)
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ def route_location(name)
return { result: { location: nil } }
end

key = T.must(name.match(/^([a-zA-Z0-9_]+)(_path|_url)$/))[1]
key = T.must(name.match(/(^.+)(_path|_url)$/))[1]

# A token could match the _path or _url pattern, but not be an actual route.
unless ::Rails.application.routes.named_routes.key?(key)
route = ::Rails.application.routes.named_routes.get(key)
unless route
return { result: { location: nil } }
end

route = ::Rails.application.routes.named_routes.get(key)

unless route&.source_location
return { result: { location: nil } }
end
Expand Down

0 comments on commit a9f2360

Please sign in to comment.