Julia 1.13: re-wrap @doc cell result as Docs.Binding - #3546
Conversation
|
Another idea:
|
|
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> |
|
Hi, with 1.13 release approaching I tested this PR (with current main merged in) - CI tests including those from MacroAnalysis are all green for both 1.12.6 and 1.13-rc1 (openSUSE Leap 15.6 Linux). So this would tick all the items in the test plan green. I am living on 1.13 for quite while now including a multitude of Pluto notebook uses, and I have seen no other hiccups. So IMHO the "unsupported" warning can be bumped and this can be merged. |
|
This is what Claude Sonnet has to say: I compared What the change doesJulia 1.13 changed Validated as working
Risk: the heuristic silently misses several common definition shapesI confirmed three concrete cases where
These aren't edge cases nobody writes — subtyped structs, abstract type hierarchies, and documented macros are all idiomatic Julia. They currently work fine on 1.12 (via the old direct- Other observations
RecommendationI would not block merging over this — it's a strict improvement over the current broken 1.13 rendering for the common cases, is well-guarded by version checks, has no security/reactivity implications, and passes existing tests. But I'd flag it for follow-up before/soon after merging:
I asked them to implement these recommendations. |
|
See #3600 |
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>
704beb1 to
75b5873
Compare
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: