Skip to content

Commit

Permalink
Fix dynamic constant path names in document symbol (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Oct 16, 2024
1 parent 0c98405 commit d2441c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def handle_all_arg_types(node, message)

arg_receiver = argument.receiver

name = arg_receiver.full_name if arg_receiver.is_a?(Prism::ConstantReadNode) ||
name = constant_name(arg_receiver) if arg_receiver.is_a?(Prism::ConstantReadNode) ||
arg_receiver.is_a?(Prism::ConstantPathNode)
next unless name

Expand Down Expand Up @@ -201,8 +201,8 @@ def handle_class_arg_types(node, message)
arguments.each do |argument|
case argument
when Prism::ConstantReadNode, Prism::ConstantPathNode
name = argument.full_name
next if name.empty?
name = constant_name(argument)
next unless name

append_document_symbol(
name: "#{message} #{name}",
Expand Down
12 changes: 12 additions & 0 deletions test/ruby_lsp_rails/document_symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ class FooModel < ApplicationRecord
assert_equal("validates_with Foo::BarClass", response[0].children[1].name)
end

test "handles dynamic constant paths" do
response = generate_document_symbols_for_source(<<~RUBY)
class FooModel < ApplicationRecord
validates_with self::FooClass
end
RUBY

assert_equal(1, response.size)
assert_equal("FooModel", response[0].name)
assert_empty(response[0].children)
end

test "correctly handles association callbacks with string and symbol argument types" do
response = generate_document_symbols_for_source(<<~RUBY)
class FooModel < ApplicationRecord
Expand Down

0 comments on commit d2441c7

Please sign in to comment.