Skip to content

Commit 579af14

Browse files
authored
avoid including source contents from @!parse directive (#1665)
# Description Make the source contents of documented objects created in `@!parse` directive the contents below the `@!parse` block. # Completed Tasks - [x] I have read the [Contributing Guide][contrib]. - [x] The pull request is complete (implemented / written). - [x] Git commits have been cleaned up (squash WIP / revert commits). - [x] I wrote tests and ran `bundle exec rake` locally (if code is attached to PR). [contrib]: https://github.com/lsegal/yard/blob/main/CONTRIBUTING.md
1 parent f8067f9 commit 579af14

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

lib/yard/tags/directives.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ def readable?
543543
# @since 0.8.0
544544
class ParseDirective < Directive
545545
def call
546+
existing = YARD::Registry.all.lazy.map(&:path).to_set if handler
546547
lang = tag.types ? tag.types.first.to_sym :
547548
(handler ? handler.parser.parser_type : :ruby)
548549
if handler && lang == handler.parser.parser_type
@@ -555,6 +556,12 @@ def call
555556
src_parser.file = handler.parser.file if handler
556557
src_parser.parse(StringIO.new(tag.text))
557558
end
559+
return unless handler
560+
YARD::Registry.all.each do |obj|
561+
next if existing.include? obj.path
562+
obj.files.each { |entry| entry[1] = handler.statement.line if entry[0] == handler.parser.file.to_s }
563+
obj.source = handler.statement.source
564+
end
558565
end
559566
end
560567

spec/tags/directives_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class A
4040
parser.file = "myfile.rb"
4141
parser.parse(StringIO.new(src))
4242
expect(Registry.at('A#foo').file).to eq 'myfile.rb'
43+
expect(Registry.at('A#foo').source.strip).to eq 'eval "def foo; end"'
4344
end
4445
end
4546
end

0 commit comments

Comments
 (0)