Skip to content

Update rdoc to 6.13.1 #2355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
rbs (4.0.0.dev)
logger
rdoc (>= 6.13)

PATH
remote: test/assets/test-gem
Expand Down Expand Up @@ -93,7 +94,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rdoc (6.11.0)
rdoc (6.13.1)
psych (>= 4.0.0)
regexp_parser (2.10.0)
rspec (3.13.0)
Expand Down
16 changes: 3 additions & 13 deletions lib/rbs/annotate/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,10 @@ def format(newline_at_end:)

def self.each_part(doc, &block)
if block
document =
case doc
when String
raise
when RDoc::Comment
document = doc.parse
when RDoc::Markup::Document
document = doc
end

if document.file
yield document
if doc.file
yield doc
else
document.each do |d|
doc.each do |d|
each_part(d, &block)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/rbs/annotate/rdoc_annotator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def annotate_decls(decls, outer: [])
def each_part(subjects, tester:)
if block_given?
subjects.each do |subject, docs|
Formatter.each_part(subject.comment) do |doc|
comment = subject.comment
raise if comment.is_a?(String)
Formatter.each_part(comment.parse) do |doc|
if tester.test_path(doc.file || raise)
yield [doc, subject]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rbs/annotate/rdoc_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def load
@stores.clear()

RDoc::RI::Paths.each(with_system_dir, with_site_dir, with_home_dir, with_gems_dir ? :latest : false, *extra_dirs.map(&:to_s)) do |path, type|
store = RDoc::Store.new(path, type)
store = RDoc::Store.new(RDoc::Options.new, path:, type:)
store.load_all

@stores << store
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc_plugin/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_method_decl(decl:, context:, outer_name: nil)
end

def parse_method_alias_decl(decl:, context:, outer_name: nil)
alias_def = RDoc::Alias.new(nil, decl.old_name.to_s, decl.new_name.to_s, nil, decl.kind == :singleton)
alias_def = RDoc::Alias.new(nil, decl.old_name.to_s, decl.new_name.to_s, nil, singleton: decl.kind == :singleton)
alias_def.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
context.add_alias(alias_def)
end
Expand All @@ -100,7 +100,7 @@ def parse_attr_decl(decl:, context:, outer_name: nil)
when ::RBS::AST::Members::AttrAccessor
'RW'
end
attribute = RDoc::Attr.new(nil, decl.name.to_s, rw, nil, decl.kind == :singleton)
attribute = RDoc::Attr.new(nil, decl.name.to_s, rw, nil, singleton: decl.kind == :singleton)
attribute.visibility = decl.visibility
attribute.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
context.add_attribute(attribute)
Expand Down
1 change: 1 addition & 0 deletions rbs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 3.1"
spec.add_dependency "logger"
spec.add_dependency "rdoc", '>= 6.13'
end
4 changes: 2 additions & 2 deletions sig/annotate/formatter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module RBS

def self.translate: (RDoc::Markup::Document) -> String?

def self.each_part: (RDoc::Markup::Document | RDoc::Comment | String) { (RDoc::Markup::Document) -> void } -> void
| (RDoc::Markup::Document | RDoc::Comment | String) -> Enumerator[RDoc::Markup::Document, void]
def self.each_part: (RDoc::Markup::Document) { (RDoc::Markup::Document) -> void } -> void
| (RDoc::Markup::Document) -> Enumerator[RDoc::Markup::Document, void]
end
end
end
2 changes: 1 addition & 1 deletion sig/annotate/rdoc_annotater.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module RBS
end

interface _WithRDocComment
def comment: () -> (RDoc::Markup::Document | RDoc::Comment | String)
def comment: () -> (RDoc::Comment | String)
end

def each_part: (Array[Object & _WithRDocComment], tester: _PathTester) { ([RDoc::Markup::Document, Object & _WithRDocComment]) -> void } -> void
Expand Down
4 changes: 2 additions & 2 deletions stdlib/rdoc/0/code_object.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module RDoc
# <!-- rdoc-file=lib/rdoc/code_object.rb -->
# Our comment
#
attr_reader comment: Markup::Document | Comment | String
attr_reader comment: Comment | String

# <!--
# rdoc-file=lib/rdoc/code_object.rb
Expand All @@ -46,6 +46,6 @@ module RDoc
# -->
# Replaces our comment with `comment`, unless it is empty.
#
def comment=: (Markup::Document | Comment | String | nil) -> (Markup::Document | Comment | String)
def comment=: (Comment | String | nil) -> (Comment | String | nil)
end
end
2 changes: 2 additions & 0 deletions stdlib/rdoc/0/comment.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module RDoc
#
attr_accessor location: String

alias file location

# <!--
# rdoc-file=lib/rdoc/comment.rb
# - new(text = nil, location = nil, language = nil)
Expand Down
76 changes: 76 additions & 0 deletions stdlib/rdoc/0/options.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
%a{annotate:rdoc:skip}
module RDoc
# <!-- rdoc-file=lib/rdoc/options.rb -->
# RDoc::Options handles the parsing and storage of options
#
# ## Saved Options
#
# You can save some options like the markup format in the `.rdoc_options` file
# in your gem. The easiest way to do this is:
#
# rdoc --markup tomdoc --write-options
#
# Which will automatically create the file and fill it with the options you
# specified.
#
# The following options will not be saved since they interfere with the user's
# preferences or with the normal operation of RDoc:
#
# * `--coverage-report`
# * `--dry-run`
# * `--encoding`
# * `--force-update`
# * `--format`
# * `--pipe`
# * `--quiet`
# * `--template`
# * `--verbose`
#
# ## Custom Options
#
# Generators can hook into RDoc::Options to add generator-specific command line
# options.
#
# When `--format` is encountered in ARGV, RDoc calls ::setup_options on the
# generator class to add extra options to the option parser. Options for custom
# generators must occur after `--format`. `rdoc --help` will list options for
# all installed generators.
#
# Example:
#
# class RDoc::Generator::Spellcheck
# RDoc::RDoc.add_generator self
#
# def self.setup_options rdoc_options
# op = rdoc_options.option_parser
#
# op.on('--spell-dictionary DICTIONARY',
# RDoc::Options::Path) do |dictionary|
# rdoc_options.spell_dictionary = dictionary
# end
# end
# end
#
# Of course, RDoc::Options does not respond to `spell_dictionary` by default so
# you will need to add it:
#
# class RDoc::Options
#
# ##
# # The spell dictionary used by the spell-checking plugin.
#
# attr_accessor :spell_dictionary
#
# end
#
# ## Option Validators
#
# OptionParser validators will validate and cast user input values. In addition
# to the validators that ship with OptionParser (String, Integer, Float,
# TrueClass, FalseClass, Array, Regexp, Date, Time, URI, etc.), RDoc::Options
# adds Path, PathArray and Template.
#
class Options
def initialize: (?untyped loaded_options) -> void
end
end
10 changes: 6 additions & 4 deletions stdlib/rdoc/0/rdoc.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ module RDoc
#
# Usually this is called by super from a subclass.
#
def initialize: (String text, String name) -> void
def initialize: (String text, String name, ?singleton: bool) -> void

# <!--
# rdoc-file=lib/rdoc/method_attr.rb
Expand Down Expand Up @@ -267,7 +267,7 @@ module RDoc
# -->
# Creates a new AnyMethod with a token stream `text` and `name`
#
def initialize: (String? text, String name) -> void
def initialize: (String? text, String name, ?singleton: bool) -> void
end

# <!-- rdoc-file=lib/rdoc/attr.rb -->
Expand All @@ -286,7 +286,7 @@ module RDoc
# Creates a new Attr with body `text`, `name`, read/write status `rw` and
# `comment`. `singleton` marks this as a class attribute.
#
def initialize: (String? text, String name, String rw, RDoc::Comment? comment, ?bool `singleton`) -> void
def initialize: (String? text, String name, String rw, RDoc::Comment? comment, ?singleton: bool) -> void
end

# <!-- rdoc-file=lib/rdoc/constant.rb -->
Expand Down Expand Up @@ -372,14 +372,16 @@ module RDoc
#
attr_accessor old_name: String

attr_reader singleton: bool

# <!--
# rdoc-file=lib/rdoc/alias.rb
# - new(text, old_name, new_name, comment, singleton = false)
# -->
# Creates a new Alias with a token stream of `text` that aliases `old_name` to
# `new_name`, has `comment` and is a `singleton` context.
#
def initialize: (String? text, String name, String old_name, RDoc::Comment? comment, ?bool `singleton`) -> void
def initialize: (String? text, String name, String old_name, RDoc::Comment? comment, ?singleton: bool) -> void
end

# <!-- rdoc-file=lib/rdoc/stats.rb -->
Expand Down
2 changes: 1 addition & 1 deletion stdlib/rdoc/0/store.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module RDoc
# -->
# Creates a new Store of `type` that will load or save to `path`
#
def initialize: (?String? path, ?Symbol? type) -> void
def initialize: (Options, ?path: String? , ?type: Symbol?) -> void

# <!--
# rdoc-file=lib/rdoc/store.rb
Expand Down
34 changes: 17 additions & 17 deletions test/rbs/annotate/rdoc_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class Hello3
assert_equal 1, klss.size
klss[0].tap do |klass|
assert_predicate klass, :documented?
assert_equal 1, klass.comment.parts.size
assert_equal 1, klass.comment.parse.parts.size

assert_nil RBS::Annotate::Formatter.translate(klass.comment)
assert_equal "Document for Hello1", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
assert_nil RBS::Annotate::Formatter.translate(klass.comment.parse)
assert_equal "Document for Hello1", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
end
end

Expand All @@ -71,8 +71,8 @@ class Hello3
klss[0].tap do |klass|
refute_predicate klass, :documented?

assert_nil RBS::Annotate::Formatter.translate(klass.comment)
assert_equal "", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
assert_nil RBS::Annotate::Formatter.translate(klass.comment.parse)
assert_equal "", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
end
end

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

assert_equal "Document (1) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parts[0])
assert_equal "Document (2) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parts[1])
assert_equal "Document (1) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0])
assert_equal "Document (2) for Hello3", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[1])
end
end
end
Expand All @@ -111,7 +111,7 @@ class Hello
assert_equal 1, consts.size
consts[0].tap do |const|
assert_equal "FOO", const.name
assert_equal "Doc for FOO", RBS::Annotate::Formatter.translate(const.comment)
assert_equal "Doc for FOO", RBS::Annotate::Formatter.translate(const.comment.parse)
end
end

Expand All @@ -121,7 +121,7 @@ class Hello
assert_equal 1, consts.size
consts[0].tap do |const|
assert_equal "VERSION", const.name
assert_equal "Doc for Hello::VERSION", RBS::Annotate::Formatter.translate(const.comment)
assert_equal "Doc for Hello::VERSION", RBS::Annotate::Formatter.translate(const.comment.parse)
end
end

Expand Down Expand Up @@ -158,7 +158,7 @@ def m5; end

ms[0].tap do |m|
assert_equal "m1", m.name
assert_equal "Doc for m1", RBS::Annotate::Formatter.translate(m.comment)
assert_equal "Doc for m1", RBS::Annotate::Formatter.translate(m.comment.parse)
end
end

Expand All @@ -167,7 +167,7 @@ def m5; end

ms[0].tap do |m|
assert_equal "m2", m.name
assert_equal "Doc for m2", RBS::Annotate::Formatter.translate(m.comment)
assert_equal "Doc for m2", RBS::Annotate::Formatter.translate(m.comment.parse)
assert_equal "m1", m.is_alias_for.name
end
end
Expand All @@ -179,7 +179,7 @@ def m5; end

ms[0].tap do |m|
assert_equal "m4", m.name
assert_equal "Doc for m4", RBS::Annotate::Formatter.translate(m.comment)
assert_equal "Doc for m4", RBS::Annotate::Formatter.translate(m.comment.parse)
end
end

Expand All @@ -188,7 +188,7 @@ def m5; end

ms[0].tap do |m|
assert_equal "m5", m.name
assert_equal "Doc for m5", RBS::Annotate::Formatter.translate(m.comment)
assert_equal "Doc for m5", RBS::Annotate::Formatter.translate(m.comment.parse)
end
end
end
Expand Down Expand Up @@ -218,7 +218,7 @@ class <<self

attrs[0].tap do |attr|
assert_equal "foo", attr.name
assert_equal "Doc for foo", RBS::Annotate::Formatter.translate(attr.comment)
assert_equal "Doc for foo", RBS::Annotate::Formatter.translate(attr.comment.parse)
assert_equal "R", attr.rw
end
end
Expand All @@ -228,7 +228,7 @@ class <<self

attrs[0].tap do |attr|
assert_equal "bar", attr.name
assert_equal "Doc for bar and baz", RBS::Annotate::Formatter.translate(attr.comment)
assert_equal "Doc for bar and baz", RBS::Annotate::Formatter.translate(attr.comment.parse)
assert_equal "RW", attr.rw
end
end
Expand All @@ -238,7 +238,7 @@ class <<self

attrs[0].tap do |attr|
assert_equal "baz", attr.name
assert_equal "Doc for bar and baz", RBS::Annotate::Formatter.translate(attr.comment)
assert_equal "Doc for bar and baz", RBS::Annotate::Formatter.translate(attr.comment.parse)
assert_equal "RW", attr.rw
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/rdoc/rbs_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class RDocPluginParserTest < Test::Unit::TestCase
def parser(content)
top_level = RDoc::TopLevel.new("a.rbs")
top_level.store = RDoc::Store.new()
top_level.store = RDoc::Store.new(RDoc::Options.new)

RBS::RDocPlugin::Parser.new(top_level, content)
end
Expand Down