Skip to content

Commit

Permalink
Handle symbol tags in method tag values
Browse files Browse the repository at this point in the history
Ensure that default values for method arguments in @!method tags don't
have their method pin get disregarded because of the extra symbol pin created.
  • Loading branch information
apiology committed Feb 17, 2025
1 parent 56558f2 commit 34b8ef8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/solargraph/source_map/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def process_directive source_position, comment_position, directive
begin
src = Solargraph::Source.load_string("def #{directive.tag.name};end", @source.filename)
region = Parser::Region.new(source: src, closure: namespace)
gen_pin = Parser.process_node(src.node, region).first.last
method_gen_pins = Parser.process_node(src.node, region).first.select { |pin| pin.is_a?(Pin::Method) }
gen_pin = method_gen_pins.last
return if gen_pin.nil?
# Move the location to the end of the line so it gets recognized
# as originating from a comment
Expand Down
12 changes: 12 additions & 0 deletions spec/source_map/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,24 @@ module Foo
class Foo
# @!method bar(baz)
# @return [String]
# @!method bing(bazzle = 'anchor')
# @return [String]
# @!method bravo(charlie = :delta)
# @return [String]
make_bar_attr
make_bing_attr
make_bravo_attr
end
))
pin = map.first_pin('Foo#bar')
expect(pin.parameter_names).to eq(['baz'])
expect(pin.return_type.tag).to eq('String')
pin = map.first_pin('Foo#bing')
expect(pin.parameter_names).to eq(['bazzle'])
expect(pin.return_type.tag).to eq('String')
pin = map.first_pin('Foo#bravo')
expect(pin.parameter_names).to eq(['charlie'])
expect(pin.return_type.tag).to eq('String')
end

it 'processes singleton method directives' do
Expand Down

0 comments on commit 34b8ef8

Please sign in to comment.