Accessing docstring of a field

Fields of a struct can be documented, but how does one retrieve the docstrings? Is it possible via ? in the REPL? MWE:

struct Foo
    "I want this docstring"
    x
end
1 Like
julia> "docstring for T type"
       struct T
           "docstring for x field"
           x
           "docstring for y field"
           y
       end
T

help?> T
search: try Type Task toq toc tic tan Text Test Tuple triu tril time tanh tand Timer tuple throw trunc trues triu! tril! trace touch take!

  docstring for T type

help?> T.x
  docstring for x field

help?> T.y
  docstring for y field
2 Likes

Looks like it only shows up if you also have docstrings for the struct itself

julia> """
        Foo docs
        """struct Foo
            "I want this docstring"
            x
        end
Foo

help?> Foo.x
  I want this docstring
1 Like

What if the type is parametric?

julia> "..."
       struct T{X,Y}
           "x"
           x::X
           "y"
           y::Y
       end
T

help?> T
search: T try Type Task tan Text Tuple time tanh tand Timer tuple throw trunc trues touch take! typeof TypeVar Threads typemin typemax trylock time_ns thisind tempdir TypeError typejoin tryparse truncate

  ...

help?> T.x
ERROR: MethodError: no method matching Base.Docs.Binding(::Type{T}, ::Symbol)
Closest candidates are:
  Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
Stacktrace:
 [1] top-level scope at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/docview.jl:355

There is an open issue for this:

1 Like