Skip to content

Display RBS type signatures in documentation#1665

Draft
st0012 wants to merge 5 commits intomasterfrom
integrate-rbs
Draft

Display RBS type signatures in documentation#1665
st0012 wants to merge 5 commits intomasterfrom
integrate-rbs

Conversation

@st0012
Copy link
Copy Markdown
Member

@st0012 st0012 commented Mar 30, 2026

Summary

  • Extract #: inline RBS annotations from comments and display them alongside method/attribute documentation
  • Load type signatures from sig/ directory (inline annotations take priority)
  • Validate annotations through RBS::Parser with warnings for invalid syntax
  • Syntax-highlight type names (blue) and built-in keywords like void/untyped (purple)
  • Link type names to their documentation pages via the search index
  • Add rbs >= 4.0.0 as a gemspec dependency, bump minimum Ruby to 3.2

Screenshots

image

Implementation

Area Details
Data model type_signature accessor on MethodAttr, Marshal v4
Parser extract_type_signature! in PrismRuby, early-return guard for comments without #:
sig/ loading RDoc::RbsSupport.load_signatures via RBS::EnvironmentLoader, merged after store.complete
Validation RBS::Parser.parse_method_type / parse_type, warnings via @options.warn
Display Aliki theme only — template, CSS, JS highlighter with type linking
Highlighting Type names (blue), builtins (purple), everything else inherits base color
Tests 17 new tests across parser, marshal, and RBS support

Follow-up work

  • Merge RBS sigs with method params: Ideally type signatures should be merged with method parameters, including information added by call_seq directives. This is significantly more complex and deferred to a future PR.
  • JRuby/TruffleRuby support: RBS has a C extension that cannot build on JRuby/TruffleRuby. This PR drops them from CI. We need to figure out how to make RDoc still work on these platforms (likely by making rbs an optional dependency with graceful degradation).

@matzbot
Copy link
Copy Markdown
Collaborator

matzbot commented Mar 30, 2026

🚀 Preview deployment available at: https://641db29f.rdoc-6cd.pages.dev (commit: 2fecc01)

st0012 added 5 commits March 30, 2026 18:08
RBS 4.0 requires Ruby >= 3.2. Bump RDoc's own minimum to match and
add `rbs >= 4.0.0` as a gemspec dependency. Bump prism minimum to
`>= 1.6.0` (required by rbs). Drop JRuby and TruffleRuby from CI
matrix (rbs has a C extension that cannot build on them).
Add `type_signature` accessor to `MethodAttr`. During Prism parsing,
extract `#:` annotation lines from comment blocks and store them on
methods and attributes. Bump Marshal to v4 for RI serialization.

Render type signatures in the aliki theme: below method headings for
methods, inline after the `[RW]` badge for attributes. Arrows use
`→` for consistency with `call_seq`. Validate annotations through
`RBS::Parser` — invalid sigs emit a warning but are still displayed.

Client-side JS highlighter colors type names (blue) and built-in
keywords like `void`/`untyped`/`bool` (purple).
`RDoc::RbsSupport` provides:
- `load_signatures` to load types from .rbs files via
  `RBS::EnvironmentLoader`
- `merge_into_store` to attach sig/ types to code objects
  (inline `#:` annotations take priority)
- `validate_method_type`/`validate_type` for syntax checking

Auto-detects `sig/` directory during generation and merges types
after `store.complete`.
The JS highlighter resolves type names against the search index and
wraps matches in <a> tags. Qualified names like Foo::Bar::Baz are
collected as single linked units. Types not found in the index
remain as unlinked <span> elements.
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.

2 participants