-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Documenting macro-generated code #13006
Conversation
3621863
to
01a4e32
Compare
@mauro3, if you happen to have some time to try this out that would be great. The following diff is all that's needed in diff --git a/src/traitdef.jl b/src/traitdef.jl
index 70d447d..efdc23c 100644
--- a/src/traitdef.jl
+++ b/src/traitdef.jl
@@ -277,7 +277,7 @@ macro traitdef(head, body)
methods::Traits.FDict
constraints::Vector{Bool}
assoctyps::Vector{Any}
- function $((name))()
+ Docs.@__doc__ function $((name))()
$assoc
new( $meths, $constr, assoctyps)
end and then docs for traits should work automatically
|
Oops, scratch that last comment, since diff --git a/src/Parameters.jl b/src/Parameters.jl
index 312c42b..821e232 100644
--- a/src/Parameters.jl
+++ b/src/Parameters.jl
@@ -286,7 +286,7 @@ function with_kw(typedef)
pack_name = symbol("pack_"*string(tn))
# Finish up
quote
- $typ
+ Docs.@__doc__ $typ
$outer_positional
$outer_copy
macro $unpack_name(ex)
Sorry for the noise. |
Cool! "asdf" @traitfn tf1{X, Y<:Int; M1Tr100{X}}(a::X, b::Y) = foofoo(a)^b The |
It is cool to get fine-grained control with the |
Thanks, that one works fine too.
I agree with @one-more-minute's comment, #11932 (comment), on this. Documenting the last thing from generated code block could lead to unintended things getting into |
Ok, that sounds good. (And if there is just one thing produced by a macro there is no ambiguity on what to document.) One last thing, is there a better error message now, which suggests to use |
Not at the moment. It's still the |
Done. Also changed it to display the original expression instead of it's expansion, which should be easier to read. |
1a237f5
to
19105d2
Compare
Will this get back-ported to 0.4? |
Seems like a good candidate since there's no way this could break anyone's code. |
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Also improve invalid doc expression error message by displaying the unexpanded form of the expression instead of its expansion. Enable docstrings for `at-enum` using the newly added macro. Fixes JuliaLang#12705.
19105d2
to
0b9ef7d
Compare
Yes, it should be fine. I've rebased and squashed the commits. Also enabled documenting |
Although not used a lot to decorate functions directly, maybe |
Not sure about needing to support
|
But that is a bug in Also, irrespective, throwing this error may still be to wrong thing to do:
|
Yeah, for |
How about we forget about |
Could perhaps use a quick look by someone familiar with the docsystem. It is quite a simple addition so getting it into 0.4 would be nice. As Stefan mentioned already, this isn't going to break anything. I'm not terribly attached to the name |
I'll take you up on it: |
Is this ready or does the name need to change? |
I'm fine with the name as is so this is ready I'd think. |
Yes, it's ready. Sorry for the noise. |
RFC: Documenting macro-generated code
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Also improve invalid doc expression error message by displaying the unexpanded form of the expression instead of its expansion. Enable docstrings for `at-enum` using the newly added macro. Fixes #12705. (cherry picked from commit 0b9ef7d) ref #13006
This adds a
@__doc__
macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly.Usage:
will attach the docstring to the 1-arg method only.
Fixes #12705.