Skip to content

Commit d2441c7

Browse files
authored
Fix dynamic constant path names in document symbol (#481)
1 parent 0c98405 commit d2441c7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def handle_all_arg_types(node, message)
141141

142142
arg_receiver = argument.receiver
143143

144-
name = arg_receiver.full_name if arg_receiver.is_a?(Prism::ConstantReadNode) ||
144+
name = constant_name(arg_receiver) if arg_receiver.is_a?(Prism::ConstantReadNode) ||
145145
arg_receiver.is_a?(Prism::ConstantPathNode)
146146
next unless name
147147

@@ -201,8 +201,8 @@ def handle_class_arg_types(node, message)
201201
arguments.each do |argument|
202202
case argument
203203
when Prism::ConstantReadNode, Prism::ConstantPathNode
204-
name = argument.full_name
205-
next if name.empty?
204+
name = constant_name(argument)
205+
next unless name
206206

207207
append_document_symbol(
208208
name: "#{message} #{name}",

test/ruby_lsp_rails/document_symbol_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,18 @@ class FooModel < ApplicationRecord
400400
assert_equal("validates_with Foo::BarClass", response[0].children[1].name)
401401
end
402402

403+
test "handles dynamic constant paths" do
404+
response = generate_document_symbols_for_source(<<~RUBY)
405+
class FooModel < ApplicationRecord
406+
validates_with self::FooClass
407+
end
408+
RUBY
409+
410+
assert_equal(1, response.size)
411+
assert_equal("FooModel", response[0].name)
412+
assert_empty(response[0].children)
413+
end
414+
403415
test "correctly handles association callbacks with string and symbol argument types" do
404416
response = generate_document_symbols_for_source(<<~RUBY)
405417
class FooModel < ApplicationRecord

0 commit comments

Comments
 (0)