Display RBS type signatures in documentation#1665
Draft
Conversation
Collaborator
|
🚀 Preview deployment available at: https://641db29f.rdoc-6cd.pages.dev (commit: 2fecc01) |
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.
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.
Summary
#:inline RBS annotations from comments and display them alongside method/attribute documentationsig/directory (inline annotations take priority)RBS::Parserwith warnings for invalid syntaxvoid/untyped(purple)rbs >= 4.0.0as a gemspec dependency, bump minimum Ruby to 3.2Screenshots
Implementation
type_signatureaccessor onMethodAttr, Marshal v4extract_type_signature!inPrismRuby, early-return guard for comments without#:RDoc::RbsSupport.load_signaturesviaRBS::EnvironmentLoader, merged afterstore.completeRBS::Parser.parse_method_type/parse_type, warnings via@options.warnFollow-up work
call_seqdirectives. This is significantly more complex and deferred to a future PR.