Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

Multiple constructors

Open dpsanders opened this issue 8 years ago • 7 comments

I am trying to document multiple constructors for BigFloat added in https://github.com/JuliaLang/julia/pull/17217/files

The only way to do this seems to be to list them manually one by one. However, all docstrings for setprecision are included with one single line in numbers.md.

Is there a way to do the same for the BigFloat constructors?

dpsanders avatar Dec 31 '16 20:12 dpsanders

They also do not seem to be seen by ?BigFloat at the REPL.

dpsanders avatar Dec 31 '16 20:12 dpsanders

setprecision docs are concatenated since there isn't a specific one that matches the signature Base.setprecision. BigFloat does have an exact match for Base.MPFR.BigFloat so that one is picked.

Solution might be to reorganise the docs for all BigFloat docstrings so that the BigFloat(x) docstring isn't attached to the type definition since there are no inner constructors there that match BigFloat(x). So either moving that main docstring to a BigFloat(x) def further down, or rewording that docstring so that it isn't specific to the single argument constructor.

(This is just from a very quick scan over that code, I'll have some more time in tomorrow/day after to look more closely.)

MichaelHatherly avatar Dec 31 '16 22:12 MichaelHatherly

Any decision on this? Automatically collecting docstrings for all constructors of a type (the same way REPL does it) would be very convenient.

fjarri avatar Nov 01 '18 23:11 fjarri

Can I bump this? This would be super useful.

rayegun avatar Nov 10 '21 01:11 rayegun

I just had kind of the same problem the other way round. When aliasing a type, say

"    Foo <: Any"
struct Foo end
"    Foo(x)"
Foo(x) = Foo()
"    (::Foo)()"
(::Foo)() = 42

AliasOfFoo = Foo

then

```@docs
AliasOfFoo
```

produces all the docstrings (with somewhat wrong heading “AliasOfFoo — Type”), although I only want the type. Maybe a syntax like

```@docs
Foo :: Type  # the type
Foo(...)  # all the constructor methods
::Foo  # all the methods of callables
```

would be a nice solution for my problem and that described above?

mgkurtz avatar May 04 '22 14:05 mgkurtz

Looking into the code, it seems like signature in Julia Base only produces Union{} for types. And callable methods and constructors are not differentiated at all. So (::Foo)(x) and Foo(x) both get signature Tuple{Any}. So, implementing my idea above would need changes in Base.Docs.

The strange behavior of AliasOfFoo stems from getdocs not finding AliasOfFoo via getmeta and thus relaxing the type comparison from == to <:. As AliasOfFoo still cannot be found, getdocs tries Foo = aliasof(AliasOfFoo), but now with <: instead of ==. So we get all docstrings now.

mgkurtz avatar May 04 '22 15:05 mgkurtz

@mgkurtz I think you've run into https://github.com/JuliaDocs/Documenter.jl/issues/558#issuecomment-507010943. The aliasing observations are useful though.

mortenpi avatar May 04 '22 23:05 mortenpi