Conversation
`show_doc` and the documentation dialog of the autocompletion were hard-wired to RDoc::RI::Driver, so other documentation backends (a manual in another language, YARD, a project-local doc store) could not plug into them without monkey-patching irb internals. `IRB.doc_providers` is the ordered list of providers they consult; it defaults to `[IRB::RDocDocumentProvider.new]`, the existing RI code moved behind a small duck type: `document(name)` returns a String or nil, and the optional `dialog_contents(name, width)` returns the lines of the completion dialog. Earlier providers win, so a library can `IRB.doc_providers.unshift(MyDocProvider.new)`. `show_doc NAME` pages the first result with IRB::Pager and prints RI's "maybe you meant" suggestions when nothing is found; `show_doc` without an argument still starts RI's interactive session. The dialog is registered whenever a provider can serve it, so a non-RDoc provider also works without `rdoc`, and the error fallback of the dialog no longer needs RDoc to render. Closes ruby#1243 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`RDocDocumentProvider#not_found_message` expanded the class part of the name to reproduce ri's "Did you mean?", so without RI data (as on CI) `show_doc String#gsub` printed "Nothing known about String" instead of "Nothing known about String#gsub" like before. Report the name as given, as show_doc always did, and keep only the "maybe you meant" suggestions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
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.
Implements the proposal in #1243: a small public extension point so that documentation backends other than RI can plug into
show_docand the documentation dialog of the autocompletion (Alt+d) without monkey-patching irb internals.API
IRB.doc_providersis the ordered list of providers consulted byshow_doc NAMEand by the completion dialog. It defaults to[IRB::RDocDocumentProvider.new], so nothing changes out of the box. A library or.irbrccan add its own provider; earlier providers win:A provider is a duck type:
IRB::RDocDocumentProvideris the existing RI code moved behind this interface (driver construction honoringIRB.conf[:EXTRA_DOC_DIRS],document,dialog_contents,interactive, andnot_found_message, which reproduces the "maybe you meant" suggestions ofri).show_docwithout an argument still starts RI's interactive session directly; it is RI-specific and does not consult providers. This is documented indoc/EXTEND_IRB.md.Changes
lib/irb/doc_provider.rb(new):IRB.doc_providersandIRB::RDocDocumentProvider.lib/irb/command/show_doc.rb: asks the providers in order and pages the first result withIRB::Pager. When nothing is found it prints RI's suggestions ("X not found, maybe you meant:" / "Nothing known about X"), or the existing "Can't display document becauserdocis not installed." warning when RDoc is missing.lib/irb/input-method.rb: the dialog (doc_dialog_contents) and the Alt+d full document (display_document) go through the providers. The dialog is registered when any provider can serve it, so a non-RDoc provider also works withoutrdoc. The error fallback from Keep completion alive when RDoc document retrieval fails #1229 is kept (a raising provider shows the error in the dialog instead of breaking completion) and no longer needs RDoc to render it.test/irb/test_doc_provider.rb(new), plus provider-based tests intest/irb/test_input_method.rbandtest/irb/test_command.rbusing stub providers, so the dialog andshow_doccode paths are now exercised even on CI without RI data.with_doc_providershelper intest/irb/helper.rb.Behavior notes
Mostly a refactor, with these visible differences:
show_doc NAMEoutput is paged byIRB::Pager(honoringIRB.conf[:USE_PAGER]) instead of RI's own pager, and uses ANSI bold on a color terminal (like the dialog already did). When stdout is not a tty the text is the same backspace-bold text as before.expand_namelike thericommand does, soshow_doc StringIshowsStringIOandshow_doc Strinlists similar classes (both printed nothing before). Unknown names are still reported as "Nothing known about NAME".show_docwithout arguments) no longer prints that warning by mistake.With this in place,
bitclust-irb(rurema/bitclust#326) can register a provider instead of a separaterefecommand, soshow_doc String#gsubshows the Japanese manual when available and falls back to RI.日本語要約
#1243 の提案の実装です。
IRB.doc_providers(既定は[IRB::RDocDocumentProvider.new])に登録したプロバイダをshow_docと補完のドキュメントダイアログ(Alt+d)が順に問い合わせます。プロバイダはdocument(name)(必須・String か nil)とdialog_contents(name, width)(任意)を持つ duck type です。既存の RI 実装はIRB::RDocDocumentProviderに移動し、show_doc引数なしの対話モードは従来どおり RI 直結です。🤖 Generated with Claude Code