Skip to content

Commit d094e76

Browse files
committed
Return value of RDoc::Attr#comment has been changed.
1 parent eac4738 commit d094e76

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

lib/rbs/annotate/formatter.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,17 @@ def self.each_part(doc, &block)
8181
end
8282
end
8383

84-
def self.translate(doc)
85-
if doc.file
84+
def self.translate(doc_or_comment)
85+
if doc_or_comment.file
8686
formatter = RDoc::Markup::ToMarkdown.new
87-
doc.accept(formatter).strip.lines.map(&:rstrip).join("\n")
87+
case doc_or_comment
88+
when RDoc::Markup::Document
89+
doc_or_comment
90+
when RDoc::Comment
91+
doc_or_comment.parse
92+
else
93+
raise "Unexpected comment class: #{doc_or_comment.class}"
94+
end.accept(formatter).strip.lines.map(&:rstrip).join("\n")
8895
end
8996
end
9097
end

sig/annotate/formatter.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module RBS
1515

1616
def format: (newline_at_end: bool) -> String
1717

18-
def self.translate: (RDoc::Markup::Document) -> String?
18+
def self.translate: (RDoc::Markup::Document | RDoc::Comment) -> String?
1919

2020
def self.each_part: (RDoc::Markup::Document | RDoc::Comment | String) { (RDoc::Markup::Document) -> void } -> void
2121
| (RDoc::Markup::Document | RDoc::Comment | String) -> Enumerator[RDoc::Markup::Document, void]

stdlib/rdoc/0/comment.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module RDoc
2020
#
2121
attr_accessor location: String
2222

23+
alias file location
24+
2325
# <!--
2426
# rdoc-file=lib/rdoc/comment.rb
2527
# - new(text = nil, location = nil, language = nil)

test/rbs/annotate/rdoc_source_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class Hello3
5757
assert_equal 1, klss.size
5858
klss[0].tap do |klass|
5959
assert_predicate klass, :documented?
60-
assert_equal 1, klass.comment.parts.size
60+
assert_equal 1, klass.comment.parse.parts.size
6161

6262
assert_nil RBS::Annotate::Formatter.translate(klass.comment)
63-
assert_equal "Document for Hello1", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
63+
assert_equal "Document for Hello1", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
6464
end
6565
end
6666

@@ -72,7 +72,7 @@ class Hello3
7272
refute_predicate klass, :documented?
7373

7474
assert_nil RBS::Annotate::Formatter.translate(klass.comment)
75-
assert_equal "", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
75+
assert_equal "", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
7676
end
7777
end
7878

@@ -82,10 +82,10 @@ class Hello3
8282
assert_equal 1, klss.size
8383
klss[0].tap do |klass|
8484
assert_predicate klass, :documented?
85-
assert_equal 2, klass.comment.parts.size
85+
assert_equal 2, klass.comment.parse.parts.size
8686

87-
assert_equal "Document (1) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
88-
assert_equal "Document (2) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parts[1])
87+
assert_equal "Document (1) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
88+
assert_equal "Document (2) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[1])
8989
end
9090
end
9191
end

0 commit comments

Comments
 (0)