File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
lib/ruby_lsp/ruby_lsp_rails Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -90,14 +90,14 @@ def route_location(name)
90
90
return { result : nil }
91
91
end
92
92
93
- key = T . must ( name . match ( /(^.+)(_path|_url)$/ ) ) [ 1 ]
93
+ match_data = name . match ( /(^.+)(_path|_url)$/ )
94
+ return { result : nil } unless match_data
95
+
96
+ key = match_data [ 1 ]
94
97
95
98
# A token could match the _path or _url pattern, but not be an actual route.
96
99
route = ::Rails . application . routes . named_routes . get ( key )
97
-
98
- unless route &.source_location
99
- return { result : nil }
100
- end
100
+ return { result : nil } unless route &.source_location
101
101
102
102
{
103
103
result : {
Original file line number Diff line number Diff line change @@ -92,6 +92,14 @@ def baz; end
92
92
assert_equal ( 3 , response [ 0 ] . range . end . line )
93
93
end
94
94
95
+ test "handles incomplete routes" do
96
+ response = generate_definitions_for_source ( <<~RUBY , { line : 0 , character : 0 } )
97
+ _path
98
+ RUBY
99
+
100
+ assert_empty ( response )
101
+ end
102
+
95
103
test "provides the definition of a custom route" do
96
104
response = generate_definitions_for_source ( <<~RUBY , { line : 0 , character : 0 } )
97
105
archive_users_path
You can’t perform that action at this time.
0 commit comments