Skip to content

Commit

Permalink
Prefer statement docstring when processing registered node (#202)
Browse files Browse the repository at this point in the history
* Prefer statement docstring when processing registered node

* Add tests

* Update CHANGELOG
  • Loading branch information
dduugg authored Apr 3, 2023
1 parent b13943d commit fcebc21
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## main

### Bug Fixes

* [#201](https://github.com/dduugg/yard-sorbet/issues/201) Caching not reloading docstring when using Sorbet signature

## 0.8.0 (2023-01-14)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion lib/yard-sorbet/handlers/sig_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def process_def(def_node)
separator = scope == :instance && def_node.type == :def ? '#' : '.'
registered = YARD::Registry.at("#{namespace}#{separator}#{def_node.method_name(true)}")
if registered
parse_node(registered, registered.docstring)
parse_node(registered, statement.docstring || registered.docstring)
# Since we're probably in an RBI file, delete the def node, which could otherwise erroneously override the
# visibility setting
NodeUtils.delete_node(def_node)
Expand Down
4 changes: 4 additions & 0 deletions spec/data/sig_handler.rbi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ module Merge

sig { returns(Integer) }
def bat; end

# new docstring
sig { returns(T::Boolean) }
def xyz; end
end
end
3 changes: 3 additions & 0 deletions spec/data/sig_handler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,8 @@ module Merge

# @return the result
def bat; end

# old doctsring
def xyz; end
end
end
4 changes: 4 additions & 0 deletions spec/yard_sorbet/handlers/sig_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
it 'merges return tag comment with sig return type' do
expect(YARD::Registry.at('Merge::A#bat').tag(:return).text).to eq('the result')
end

it 'overwrites the prior docstring when a new docstring exists' do
expect(YARD::Registry.at('Merge::A#xyz').docstring).to eq('new docstring')
end
end

describe 'attaching to method' do
Expand Down

0 comments on commit fcebc21

Please sign in to comment.