Why does field docstring generation depend on where it was defined?
In a file:
# MyModule.jl
module MyModule
"A docstring"
struct A
    "a docstring"
    a::Int64
end
end
julia> include("MyModule.jl")
Main.MyModule
help?> MyModule.A.a
  a docstring
In the REPL
julia> ex = :(struct B
       "b docstring"
       b::Int64
       end);
julia> @eval $ex
help?> B.b
  B has fields b.
             
            
              
              
              2 Likes
            
            
           
          
            
            
              Bump, just in case anybody knows
             
            
              
              
              
            
            
           
          
            
            
              I don’t know the underlying reason why, but observe in the REPL:
julia> struct B
           "b docstring"
            b::Int64
       end;
help?> B.b
  B has fields b.
while
julia> "Module B"
        struct B
           "b docstring"
            b::Int64
       end
help?> B.b
  b docstring
So it seems it’s not include versus REPL, but the use of a docstring for the module definition.
You can “see” the docstring registration via Docs.meta(Main).
Actually, possibly related to an open issue (from 2016):
docstrings for inner constructors are ignored · Issue #16730 · JuliaLang/julia · GitHub
             
            
              
              
              2 Likes