Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created March 1, 2022 17:45
Show Gist options
  • Save jkrumbiegel/061df38368f114a5870ae4d6074307b5 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/061df38368f114a5870ae4d6074307b5 to your computer and use it in GitHub Desktop.
using Markdown
Docs.getdoc(s::typeof(scatter)) = plot_func_docs(s)
Docs.getdoc(h::typeof(heatmap)) = plot_func_docs(h)
function plot_func_docs(plotfunc)
T = Combined{plotfunc}
io = IOBuffer()
trait = Makie.conversion_trait(T)
println(io, "# Type signatures")
println(io, "`$plotfunc` has the conversion trait `$trait` which means that it accepts the following positional arguments:\n")
conversion_trait_docs(io, trait)
Markdown.parse(String(take!(io)))
end
function conversion_trait_docs(io, trait)
ms = methodswith(typeof(trait), Makie.convert_arguments, supertypes = true)
argspecs = [method_argspec(m)[2:end] for m in ms]
sort!(argspecs, by = length)
for argspec in argspecs
print(io, "- ")
for (i, arg) in enumerate(argspec)
print_sig(io, arg)
i < length(argspec) && print(io, ", ")
end
println(io)
end
end
function print_sig(io, pair)
print(io, pair[1], "::`", pair[2], "`")
end
function method_argspec(m::Method)
argnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), m.slot_syms)
isempty(argnames) && return []
f(x::Type) = x isa UnionAll ? x.body.parameters[2:end] : x.parameters[2:end]
try
[a=>b for (a,b) in zip(argnames[2:m.nargs], f(m.sig))]
catch e
[]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment