Skip to content

Commit 665ac3c

Browse files
authored
Account for dynamic constant paths in document symbol (#437)
1 parent e815ef6 commit 665ac3c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def handle_all_arg_types(node, message)
151151
selection_range: range_from_location(argument.location),
152152
)
153153
when Prism::ConstantReadNode, Prism::ConstantPathNode
154-
name = argument.full_name
154+
name = constant_name(argument)
155+
next unless name
155156
next if name.empty?
156157

157158
append_document_symbol(

test/ruby_lsp_rails/document_symbol_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ class FooModel < ApplicationRecord
415415
assert_equal("belongs_to :baz", response[0].children[1].name)
416416
end
417417

418+
test "does not break with incomplete constant path nodes" do
419+
response = generate_document_symbols_for_source(<<~RUBY)
420+
class FooModel < ApplicationRecord
421+
validate var::Foo
422+
end
423+
RUBY
424+
425+
assert_equal(1, response.size)
426+
assert_equal("FooModel", response[0].name)
427+
assert_empty(response[0].children)
428+
end
429+
418430
private
419431

420432
def generate_document_symbols_for_source(source)

0 commit comments

Comments
 (0)