Parse RBS files as RDoc input#1728
Open
st0012 wants to merge 10 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a built-in RDoc::Parser::RBS so .rbs files can be parsed as first-class RDoc inputs (instead of relying on the rbs gem’s runtime rdoc/discover hook), while also refining how sig/**/*.rbs files are auto-discovered and reloaded for type-signature merging and live preview.
Changes:
- Introduces
lib/rdoc/parser/rbs.rband registers it so.rbsfiles are parsed directly by RDoc. - Separates “auto-discovered signature files” (
sig/**/*.rbs) from explicitly selected.rbsdocumentation inputs for signature loading + live-reload bookkeeping. - Refactors live server change detection/reload flow and extends
RDoc::Contextto support qualified module/constant paths.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/rdoc/rdoc_server_test.rb | Extends live-reload tests to cover parsing/reloading .rbs docs + signatures. |
| test/rdoc/rdoc_rdoc_test.rb | Adds integration tests for explicit .rbs inputs, auto-discovery rules, and skipping released rbs discovery hook. |
| test/rdoc/rdoc_context_test.rb | Adds coverage for qualified/absolute module additions and constant owner resolution helpers. |
| test/rdoc/parser/rbs_test.rb | New unit tests for the built-in RBS parser mapping into RDoc code objects. |
| lib/rdoc/server.rb | Refactors watcher change tracking and adds dedicated RBS signature reload path. |
| lib/rdoc/rdoc.rb | Renames/refines auto-discovered signature loading APIs and skips released rbs discovery hook. |
| lib/rdoc/parser/rbs.rb | New built-in .rbs parser implementation. |
| lib/rdoc/parser.rb | Requires the new RBS parser so it registers with RDoc::Parser. |
| lib/rdoc/code_object/context.rb | Adds helpers to build module paths + support qualified names in add_module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
🚀 Preview deployment available at: https://3781a396.rdoc-6cd.pages.dev (commit: 21e9e35) |
| You'll find information on the various formatting tricks you can use in comment blocks in the documentation this generates. | ||
|
|
||
| RDoc uses file extensions to determine how to process each file. File names ending `.rb` and `.rbw` are assumed to be Ruby source. Files ending `.c` are parsed as C files. All other files are assumed to contain just Markup-style markup (with or without leading `#` comment markers). If directory names are passed to RDoc, they are scanned recursively for C and Ruby source files only. | ||
| RDoc uses file extensions to determine how to process each file. File names ending `.rb` and `.rbw` are assumed to be Ruby source. Files ending `.c` are parsed as C files. Files ending `.rbs` are parsed as RBS signature files. All other files are assumed to contain just Markup-style markup (with or without leading `#` comment markers). If directory names are passed to RDoc, they are scanned recursively for C, Ruby, and RBS source files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RBS describes Ruby program structure, including classes, modules, methods, attributes, constants, inheritance, and mixins. RDoc already has a parser extension model where parser classes register the file names they handle through
parse_files_matching(RDoc::Parser docs).Today,
.rbsdocumentation parsing is provided by therbsgem through anrdoc/discoverhook that definesRDoc::Parser::RBSat runtime (rbs discovery hook). That keeps RBS documentation support coupled to a separately released plugin even though RDoc now already has RBS as a dependency for type-signature display (ruby/rdoc#1665). It also means RDoc internal API changes can break the released plugin, as seen in the compatibility discussion aroundRDoc::Alias,RDoc::AnyMethod, andRDoc::Attr.Solution
This intentionally moves the existing RBS RDoc plugin shape into RDoc rather than introducing an unrelated parser design. The new
RDoc::Parser::RBSis adapted fromRBS::RDocPlugin::Parser, which already parses RBS files withRBS::Parser.parse_signatureand maps RBS AST declarations into RDoc code objects (RBS plugin parser, RBS parser architecture).The RDoc-side parser registers
.rbsfiles as first-class RDoc input and keeps the same broad mapping model for classes, modules, interfaces, methods, attributes, constants, includes, extends, and method aliases. On top of the RBS plugin implementation, this PR adds the integration fixes needed inside RDoc: currentRDoc::Alias/RDoc::AnyMethod/RDoc::Attrconstructor calls after the API change discussed in ruby/rdoc#1711, extension of existing Ruby-source documentation when matching RBS declarations are parsed, and separation between.rbsfiles selected as documentation input andsig/**/*.rbsfiles auto-discovered for type-signature merging from ruby/rdoc#1665.During RubyGems extension discovery, RDoc skips the released
rbsgem’srdoc/discoverhook so the built-in parser owns.rbsparsing when available (rbs discovery hook).Scope
This covers the common RBS declaration/member forms needed for documentation generation: classes, modules, interfaces, methods, attributes, constants, includes, extends, and method aliases. Remaining RBS-specific behavior that needs more design, such as class/module aliases, standalone visibility members, directive preprocessing, and
self?method expansion, is left as explicit follow-up TODOs in the parser.