Skip to content

Commit 1cd6e62

Browse files
authored
Fix comment_location for merged ClassModule (#1531)
Fix #1530
1 parent d676630 commit 1cd6e62

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/rdoc/code_object/class_module.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,12 @@ def merge(class_module)
477477
document = document.merge other_document
478478

479479
@comment = RDoc::Comment.from_document(document)
480-
@comment_location = document
480+
481+
@comment_location = if document.parts.first.is_a?(RDoc::Markup::Document)
482+
document.parts.map { |doc| [doc, doc.file] }
483+
else
484+
[[document, document.file]]
485+
end
481486
end
482487

483488
cm = class_module

test/rdoc/code_object/class_module_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,10 @@ def test_merge
655655
tl = @store.add_file 'one.rb'
656656
p1 = tl.add_class RDoc::NormalClass, 'Parent'
657657
c1 = p1.add_class RDoc::NormalClass, 'Klass'
658+
c1.add_comment 'comment1', tl
658659

659660
c2 = RDoc::NormalClass.new 'Klass'
661+
c2.add_comment 'comment2', tl
660662

661663
c2.merge c1
662664

@@ -665,6 +667,10 @@ def test_merge
665667

666668
assert c1.current_section, 'original current_section'
667669
assert c2.current_section, 'merged current_section'
670+
671+
comment, location = c2.comment_location.first
672+
assert_kind_of RDoc::Markup::Document, comment
673+
assert_equal tl.relative_name, location
668674
end
669675

670676
def test_merge_attributes

0 commit comments

Comments
 (0)