File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
lib/ruby_lsp/ruby_lsp_rails Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -160,8 +160,10 @@ def on_class_node_leave(node)
160
160
161
161
sig { returns ( T . nilable ( T ::Boolean ) ) }
162
162
def controller?
163
- class_name , superclass_name = T . must ( @constant_name_stack . last )
164
- class_name . end_with? ( "Controller" ) && superclass_name &.end_with? ( "Controller" )
163
+ class_name , superclass_name = @constant_name_stack . last
164
+ return false unless class_name && superclass_name
165
+
166
+ class_name . end_with? ( "Controller" ) && superclass_name . end_with? ( "Controller" )
165
167
end
166
168
167
169
sig { params ( node : Prism ::DefNode ) . void }
Original file line number Diff line number Diff line change @@ -303,6 +303,15 @@ def index
303
303
assert_match ( "config/routes.rb" , path )
304
304
end
305
305
306
+ test "doesn't break when analyzing a file without a class" do
307
+ response = generate_code_lens_for_source ( <<~RUBY )
308
+ def index
309
+ end
310
+ RUBY
311
+
312
+ assert_empty ( response )
313
+ end
314
+
306
315
private
307
316
308
317
attr_reader :ruby
You can’t perform that action at this time.
0 commit comments