Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix REPL summary for types #39358

Merged
merged 2 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 51 additions & 29 deletions stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,44 +264,66 @@ function summarize(io::IO, λ::Function, binding::Binding)
println(io, "```\n", methods(λ), "\n```")
end

function summarize(io::IO, T::DataType, binding::Binding)
function summarize(io::IO, TT::Type, binding::Binding)
println(io, "# Summary")
println(io, "```")
println(io,
T.abstract ? "abstract type" :
T.mutable ? "mutable struct" :
Base.isstructtype(T) ? "struct" : "primitive type",
" ", T, " <: ", supertype(T)
)
println(io, "```")
if !T.abstract && T.name !== Tuple.name && !isempty(fieldnames(T))
println(io, "# Fields")
T = Base.unwrap_unionall(TT)
if T isa DataType
println(io, "```")
pad = maximum(length(string(f)) for f in fieldnames(T))
for (f, t) in zip(fieldnames(T), T.types)
println(io, rpad(f, pad), " :: ", t)
end
println(io, "```")
end
if !isempty(subtypes(T))
println(io, "# Subtypes")
print(io,
T.abstract ? "abstract type " :
T.mutable ? "mutable struct " :
Base.isstructtype(T) ? "struct " :
"primitive type ")
supert = supertype(T)
println(io, T)
println(io, "```")
for t in subtypes(T)
println(io, t)
if !T.abstract && T.name !== Tuple.name && !isempty(fieldnames(T))
println(io, "# Fields")
println(io, "```")
pad = maximum(length(string(f)) for f in fieldnames(T))
for (f, t) in zip(fieldnames(T), T.types)
println(io, rpad(f, pad), " :: ", t)
end
println(io, "```")
end
println(io, "```")
end
if supertype(T) != Any
println(io, "# Supertype Hierarchy")
println(io, "```")
Base.show_supertypes(io, T)
println(io)
println(io, "```")
subt = subtypes(TT)
if !isempty(subt)
println(io, "# Subtypes")
println(io, "```")
for t in subt
println(io, t)
end
println(io, "```")
end
if supert != Any
println(io, "# Supertype Hierarchy")
println(io, "```")
Base.show_supertypes(io, T)
println(io)
println(io, "```")
end
elseif T isa Union
println(io, "`", binding, "` is of type `", typeof(TT), "`.\n")
println(io, "# Union Composed of Types")
for T1 in Base.uniontypes(T)
println(io, " - `", Base.rewrap_unionall(T1, TT), "`")
end
else # unreachable?
println(io, "`", binding, "` is of type `", typeof(TT), "`.\n")
end
end

function summarize(io::IO, m::Module, binding::Binding)
println(io, "No docstring found for module `", m, "`.\n")
exports = filter!(!=(nameof(m)), names(m))
if isempty(exports)
println(io, "Module does not export any names.")
else
println(io, "# Exported names:")
print(io, " `")
join(io, exports, "`, `")
println(io, "`")
end
end

function summarize(io::IO, @nospecialize(T), binding::Binding)
Expand Down
Loading