# Accessing docstring of a field

**URL:** https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830
**Category:** General Usage
**Tags:** question
**Created:** [July 13, 2017, 8:43am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830 "2017-07-13T08:43:19Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 13, 2017, 8:43am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/1 "2017-07-13T08:43:20Z")

</div>

Fields of a `struct` can be [documented](https://docs.julialang.org/en/latest/manual/documentation/#Types-1), but how does one retrieve the docstrings? Is it possible via `?` in the REPL? MWE:

```julia
struct Foo
    "I want this docstring"
    x
end

```

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [July 13, 2017, 8:53am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/2 "2017-07-13T08:53:50Z")

</div>

```julia
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

```

---

<div class="post-metadata">

### Author: ![darwindarak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darwindarak/32/8205_2.png) [@darwindarak](https://discourse.julialang.org/u/darwindarak)
#### Post date: [July 13, 2017, 11:47am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/3 "2017-07-13T11:47:19Z")

</div>

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

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

help?> Foo.x
  I want this docstring

```

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [June 19, 2019, 8:27am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/4 "2019-06-19T08:27:06Z")

</div>

What if the type is parametric?

```julia
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

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 19, 2019, 8:57am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/5 "2019-06-19T08:57:35Z")

</div>

There is an open issue for this:

[https://github.com/JuliaLang/julia/issues/29478](https://github.com/JuliaLang/julia/issues/29478)

---

<div class="post-metadata">

### Author: ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)
#### Post date: [January 18, 2023, 9:03am UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/6 "2023-01-18T09:03:36Z")

</div>

I am reviving an old thread but I think the subject is very relevant.

Is there a way to access the field docstrings programmatically without using the interactive help in the REPL?

I can access the basic documentation of the struct either with `Main.Docs.Binding(Main, :T)` or with `@doc T` but I didn’t find out how to extract the docstring for the field `T.x` programmatically

---

<div class="post-metadata">

### Author: ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)
#### Post date: [February 10, 2023, 1:46pm UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/7 "2023-02-10T13:46:20Z")

</div>

I finally got some time to try and search for this a bit more in detail.

The function for accessing the docstring of a field is called `fielddoc` and is inside the `REPL` module:

> <https://github.com/JuliaLang/julia/blob/3db0cc20eba14978c45cd91f05a9b89b1dc0e38a/stdlib/REPL/src/docview.jl#L562-L588>

---

<div class="post-metadata">

### Author: ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)
#### Post date: [March 2, 2023, 5:35pm UTC](https://discourse.julialang.org/t/accessing-docstring-of-a-field/4830/8 "2023-03-02T17:35:36Z")

</div>

I found this thread looking to see if there is a way to get VS Code to show the field docstring when hovering on a field. From the above, it seems like it should be feasible. Does anyone know if it can be enabled?
