Julia 1.13: re-wrap @doc cell result as Docs.Binding#3546
Draft
pankgeorg wants to merge 3 commits into
Draft
Conversation
JuliaLang/julia#59882 changed `@doc` to return the documented value (e.g. the function itself) instead of a `Docs.Binding`. Pluto's docstring cell output relies on dispatching on `Base.Docs.Binding` via `format_output`, so on 1.13 documented function cells now render as "f (generic function with N methods)" instead of the rich docstring view. Causes the test failures in #3449. Detect the pre-macroexpansion `@doc` macrocall, extract the bound name, and re-wrap the cell result as `Docs.Binding(workspace, name)` so the existing display path is preserved. No-op on Julia < 1.13. Refs JuliaLang/julia#60681 (closed as not planned), #3449, #3389. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pluto's Parse.jl always returns Expr(:toplevel, LineNumberNode, inner), so the original_expr seen by run_expression is wrapped — the earlier helper only inspected a bare :macrocall and returned nothing for the real shape, which is why the test/MacroAnalysis.jl "Doc strings" assertions still failed on 1.13 CI. Walk past :toplevel/:block wrappers (ignoring LineNumberNodes) before checking for the @doc macrocall. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doc_target_name returned nothing for `Expr(:., :Base, QuoteNode(:conj))`, so the cell "An empty conjugate"\nBase.conj() = x left its result as `nothing` on 1.13 and the last two MacroAnalysis.jl "Doc strings" assertions kept failing. Pick the rightmost symbol from a qualified name; Docs.Binding in any workspace resolves to the same docs via Docs.aliasof, so a workspace-rooted binding still pulls in Base.conj's docstring plus the new one we added. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
Another idea:
|
Member
|
Little nsippet <div style="
font-family: JuliaMono;
padding: .4em .4em;
font-size: .8rem;
">
<span style='font-style: italic; opacity: .8;'>function</span>
<span style='font-weight: bold;'>hello_world</span>
<a style='
font-family: system-ui;
margin-inline-start: 2ch;
' href="#">(View docs)</a>
</div> |
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
Restore the docstring-as-cell-output rendering on Julia 1.13+ that was broken by JuliaLang/julia#59882. Fixes the failing assertions in #3449; part of the #3389 umbrella. Continues — but does not stack on — the closed #3452, which had been abandoned because the author could not pin down the upstream behavior change.
What changed in Julia 1.13
Same parsed expression, different result:
@doc str defnow returns the value ofdefinstead of aBase.Docs.Binding(JuliaLang/julia#60681, closed as not planned). Pluto'sformat_output(::Base.Docs.Binding)dispatch no longer fires, so documented function cells render asf (generic function with N methods)rather than the docstring HTML.Docs.doc(binding)itself still works correctly on 1.13 and aggregates all method docstrings as before — only the cell result type changed.The fix
Detect the (pre-macroexpansion)
@docmacrocall inrun_expression, extract the bound name from the definition, and re-wrap the result asDocs.Binding(workspace, name)before storing incell_results. This puts the cell back on the existing rendering path; no display-side changes required.Docs.Binding).CapturedExceptionresults so error rendering is untouched.f(x) = …,function f end,f(::T) where T, parametric methods,struct,macro,module,const.Test plan
test/MacroAnalysis.jl"Doc strings" testset (the 11 failing assertions from Julia 1.13 tests: Macro analysis - docstrings #3449) passes on Julia 1.13."docstring"\nf(::Bool) = 1, verify the rich docstring panel renders.Out of scope (follow-ups from #3389)
warn_julia_compat()insrc/Pluto.jlstill warns on 1.13 — should be bumped to 1.14 once the testset is green.Try this Pull Request!
Open Julia and type: