Skip to content

Parse RBS files as RDoc input#1728

Open
st0012 wants to merge 10 commits into
ruby:masterfrom
st0012:codex/native-rbs-parser
Open

Parse RBS files as RDoc input#1728
st0012 wants to merge 10 commits into
ruby:masterfrom
st0012:codex/native-rbs-parser

Conversation

@st0012

@st0012 st0012 commented Jun 14, 2026

Copy link
Copy Markdown
Member

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, .rbs documentation parsing is provided by the rbs gem through an rdoc/discover hook that defines RDoc::Parser::RBS at 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 around RDoc::Alias, RDoc::AnyMethod, and RDoc::Attr.

Solution

This intentionally moves the existing RBS RDoc plugin shape into RDoc rather than introducing an unrelated parser design. The new RDoc::Parser::RBS is adapted from RBS::RDocPlugin::Parser, which already parses RBS files with RBS::Parser.parse_signature and maps RBS AST declarations into RDoc code objects (RBS plugin parser, RBS parser architecture).

The RDoc-side parser registers .rbs files 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: current RDoc::Alias/RDoc::AnyMethod/RDoc::Attr constructor 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 .rbs files selected as documentation input and sig/**/*.rbs files auto-discovered for type-signature merging from ruby/rdoc#1665.

During RubyGems extension discovery, RDoc skips the released rbs gem’s rdoc/discover hook so the built-in parser owns .rbs parsing 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.

@st0012 st0012 requested a deployment to fork-preview-protection June 14, 2026 16:44 — with GitHub Actions Waiting
@st0012 st0012 marked this pull request as ready for review June 14, 2026 16:48
Copilot AI review requested due to automatic review settings June 14, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.rb and registers it so .rbs files are parsed directly by RDoc.
  • Separates “auto-discovered signature files” (sig/**/*.rbs) from explicitly selected .rbs documentation inputs for signature loading + live-reload bookkeeping.
  • Refactors live server change detection/reload flow and extends RDoc::Context to 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.

Comment thread lib/rdoc/parser/rbs.rb
Comment thread lib/rdoc/server.rb
@st0012 st0012 deployed to fork-preview-protection June 14, 2026 17:13 — with GitHub Actions Active
@matzbot

matzbot commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

🚀 Preview deployment available at: https://3781a396.rdoc-6cd.pages.dev (commit: 21e9e35)

Copilot AI review requested due to automatic review settings June 14, 2026 21:20
@st0012 st0012 requested a deployment to fork-preview-protection June 14, 2026 21:20 — with GitHub Actions Waiting

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread lib/rdoc/server.rb
Comment thread README.md
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants