Skip to content

Commit

Permalink
Block infers yieldself from chain
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Jan 21, 2025
1 parent 7f276ca commit 2c335e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/solargraph/pin/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def binder_or_nil api_map
if receiver_pin && receiver_pin.docstring
ys = receiver_pin.docstring.tag(:yieldself)
if ys && ys.types && !ys.types.empty?
return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace).self_to(receiver_pin.full_context.namespace)
target = if chain.links.first.is_a?(Source::Chain::Constant)
receiver_pin.full_context.namespace
else
full_context.namespace
end
return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace).self_to(target)
end
end
nil
Expand Down
20 changes: 20 additions & 0 deletions spec/source_map/clip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,26 @@ def bar; end
expect(clip.complete.pins.map(&:path)).to include('Par#hidden')
end

it 'processes @yieldself from blocks in class method calls' do
source = Solargraph::Source.load_string(%(
class Par
# @yieldself [self]
def self.process; end
end
class Sub < Par
def local; end
process do
loc
end
end
), 'file.rb')
api_map = Solargraph::ApiMap.new
api_map.map source
clip = api_map.clip_at('file.rb', [9, 12])
expect(clip.complete.pins.map(&:path)).to include('Sub#local')
end

it "processes @yieldpublic tags in completions" do
source = Solargraph::Source.load_string(%(
class Par
Expand Down

0 comments on commit 2c335e5

Please sign in to comment.