From 5fba43dcf38c5146c4e3011ad6bd830b23fa1abc Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 24 Mar 2025 17:34:40 +0900 Subject: [PATCH 01/10] Limit to 6.13 or higher --- Gemfile.lock | 3 ++- rbs.gemspec | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a3f0d3b90..78d512976 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: rbs (3.9.5) logger + rdoc (>= 6.13) PATH remote: test/assets/test-gem @@ -95,7 +96,7 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) - rdoc (6.11.0) + rdoc (6.13.0) psych (>= 4.0.0) regexp_parser (2.10.0) rspec (3.13.0) diff --git a/rbs.gemspec b/rbs.gemspec index a95dd6822..6435acbb2 100644 --- a/rbs.gemspec +++ b/rbs.gemspec @@ -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 From 22111fe1834a306fad89f950c9b9a0c79f50bc45 Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 24 Mar 2025 17:35:31 +0900 Subject: [PATCH 02/10] `RDoc::Store.new` interface has been changed. --- lib/rbs/annotate/rdoc_source.rb | 2 +- stdlib/rdoc/0/options.rbs | 6 ++++++ stdlib/rdoc/0/store.rbs | 2 +- test/rbs/rdoc/rbs_parser_test.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 stdlib/rdoc/0/options.rbs diff --git a/lib/rbs/annotate/rdoc_source.rb b/lib/rbs/annotate/rdoc_source.rb index f47f212fa..f4ba46dfa 100644 --- a/lib/rbs/annotate/rdoc_source.rb +++ b/lib/rbs/annotate/rdoc_source.rb @@ -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 diff --git a/stdlib/rdoc/0/options.rbs b/stdlib/rdoc/0/options.rbs new file mode 100644 index 000000000..04c8b46c4 --- /dev/null +++ b/stdlib/rdoc/0/options.rbs @@ -0,0 +1,6 @@ +%a{annotate:rdoc:skip} +module RDoc + class Options + def initialize: (?untyped loaded_options) -> void + end +end diff --git a/stdlib/rdoc/0/store.rbs b/stdlib/rdoc/0/store.rbs index ceeb1f168..a48c95bd5 100644 --- a/stdlib/rdoc/0/store.rbs +++ b/stdlib/rdoc/0/store.rbs @@ -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 # # 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 # @@ -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 # @@ -372,6 +372,8 @@ module RDoc # attr_accessor old_name: String + attr_reader singleton: bool + # From 71921fdfb9607a9415dd8a2137b81493a50cff8d Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 24 Mar 2025 17:51:09 +0900 Subject: [PATCH 05/10] Add doc --- stdlib/rdoc/0/options.rbs | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/stdlib/rdoc/0/options.rbs b/stdlib/rdoc/0/options.rbs index 04c8b46c4..c656dfbd2 100644 --- a/stdlib/rdoc/0/options.rbs +++ b/stdlib/rdoc/0/options.rbs @@ -1,5 +1,75 @@ %a{annotate:rdoc:skip} module RDoc + # + # 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 From 152a2eadcc30b58de27832ddeddb1544071bfd51 Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 28 Mar 2025 22:51:53 +0900 Subject: [PATCH 06/10] Simplify object variation --- lib/rbs/annotate/formatter.rb | 29 ++++++--------------------- lib/rbs/annotate/rdoc_annotator.rb | 4 +++- sig/annotate/formatter.rbs | 6 +++--- sig/annotate/rdoc_annotater.rbs | 2 +- stdlib/rdoc/0/code_object.rbs | 4 ++-- test/rbs/annotate/rdoc_source_test.rb | 22 ++++++++++---------- 6 files changed, 26 insertions(+), 41 deletions(-) diff --git a/lib/rbs/annotate/formatter.rb b/lib/rbs/annotate/formatter.rb index 16cc48cd0..c53124e27 100644 --- a/lib/rbs/annotate/formatter.rb +++ b/lib/rbs/annotate/formatter.rb @@ -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 @@ -81,17 +71,10 @@ def self.each_part(doc, &block) end end - def self.translate(doc_or_comment) - if doc_or_comment.file + def self.translate(doc) + if doc.file formatter = RDoc::Markup::ToMarkdown.new - case doc_or_comment - when RDoc::Markup::Document - doc_or_comment - when RDoc::Comment - doc_or_comment.parse - else - raise "Unexpected comment class: #{doc_or_comment.class}" - end.accept(formatter).strip.lines.map(&:rstrip).join("\n") + doc.accept(formatter).strip.lines.map(&:rstrip).join("\n") end end end diff --git a/lib/rbs/annotate/rdoc_annotator.rb b/lib/rbs/annotate/rdoc_annotator.rb index 68c06241b..06958998f 100644 --- a/lib/rbs/annotate/rdoc_annotator.rb +++ b/lib/rbs/annotate/rdoc_annotator.rb @@ -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 diff --git a/sig/annotate/formatter.rbs b/sig/annotate/formatter.rbs index 3b8336649..1fb31f079 100644 --- a/sig/annotate/formatter.rbs +++ b/sig/annotate/formatter.rbs @@ -15,10 +15,10 @@ module RBS def format: (newline_at_end: bool) -> String - def self.translate: (RDoc::Markup::Document | RDoc::Comment) -> String? + 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 diff --git a/sig/annotate/rdoc_annotater.rbs b/sig/annotate/rdoc_annotater.rbs index 872c38430..5cb4dc712 100644 --- a/sig/annotate/rdoc_annotater.rbs +++ b/sig/annotate/rdoc_annotater.rbs @@ -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 diff --git a/stdlib/rdoc/0/code_object.rbs b/stdlib/rdoc/0/code_object.rbs index 2a9f37f3d..af7f631f7 100644 --- a/stdlib/rdoc/0/code_object.rbs +++ b/stdlib/rdoc/0/code_object.rbs @@ -30,7 +30,7 @@ module RDoc # # Our comment # - attr_reader comment: Markup::Document | Comment | String + attr_reader comment: Comment | String # # 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 diff --git a/test/rbs/annotate/rdoc_source_test.rb b/test/rbs/annotate/rdoc_source_test.rb index 8da51f224..b9f4cd792 100644 --- a/test/rbs/annotate/rdoc_source_test.rb +++ b/test/rbs/annotate/rdoc_source_test.rb @@ -59,7 +59,7 @@ class Hello3 assert_predicate klass, :documented? assert_equal 1, klass.comment.parse.parts.size - assert_nil RBS::Annotate::Formatter.translate(klass.comment) + 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 @@ -71,7 +71,7 @@ class Hello3 klss[0].tap do |klass| refute_predicate klass, :documented? - assert_nil RBS::Annotate::Formatter.translate(klass.comment) + assert_nil RBS::Annotate::Formatter.translate(klass.comment.parse) assert_equal "", RBS::Annotate::Formatter.translate(klass.comment.parse.parts[0]) end end @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -218,7 +218,7 @@ class < Date: Mon, 31 Mar 2025 23:06:31 +0900 Subject: [PATCH 07/10] Update rdoc to 6.13.1 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 78d512976..9aa847906 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,7 +96,7 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) - rdoc (6.13.0) + rdoc (6.13.1) psych (>= 4.0.0) regexp_parser (2.10.0) rspec (3.13.0) From f6e98c7924e55cb6efbe5d2907b767d0632b7d7b Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 7 Apr 2025 22:32:43 +0900 Subject: [PATCH 08/10] Use `gem` instead of runtime dependency --- lib/rdoc/discover.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rdoc/discover.rb b/lib/rdoc/discover.rb index c5f4a3b50..f6816143f 100644 --- a/lib/rdoc/discover.rb +++ b/lib/rdoc/discover.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true begin - gem 'rdoc', '~> 6.4' + gem 'rdoc', '~> 6.13' require 'rdoc_plugin/parser' module RDoc class Parser From d137bc6fdd7a53834c724cc01c0ee2ce8f52c23a Mon Sep 17 00:00:00 2001 From: ksss Date: Wed, 26 Nov 2025 11:13:05 +0900 Subject: [PATCH 09/10] Resolve conflict of dependency --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a7f4a9b5e..c0d72503b 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem "json-schema" gem "goodcheck" gem 'digest' gem 'tempfile' -gem "rdoc", "~> 6.11.0" +gem "rdoc" gem "fileutils" gem "raap" gem "activesupport", "~> 7.0" diff --git a/Gemfile.lock b/Gemfile.lock index 9aa847906..22d815511 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -203,7 +203,7 @@ DEPENDENCIES rake-compiler rbs! rbs-amber! - rdoc (~> 6.11.0) + rdoc rspec rubocop rubocop-on-rbs From 61cfac3816d0541d979d2c152d8ff4dd60fa635e Mon Sep 17 00:00:00 2001 From: ksss Date: Wed, 26 Nov 2025 14:25:39 +0900 Subject: [PATCH 10/10] Remove dependency --- Gemfile.lock | 1 - rbs.gemspec | 1 - 2 files changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 22d815511..780bc67c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,6 @@ PATH specs: rbs (3.9.5) logger - rdoc (>= 6.13) PATH remote: test/assets/test-gem diff --git a/rbs.gemspec b/rbs.gemspec index 6435acbb2..a95dd6822 100644 --- a/rbs.gemspec +++ b/rbs.gemspec @@ -46,5 +46,4 @@ 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