-
Notifications
You must be signed in to change notification settings - Fork 483
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
Resolve @ref
bindings in current module and Main
#2470
Conversation
@ref
bindings in current module _and_ Main@ref
bindings in current module and Main
This is ready for feedback, although as I mentioned in #2462 (comment), I might want to test this out "in production" for a little bit. Before this can be merged, I should probably add a specific test. This PR would probably also be a good opportunity to actually document how the bindings for |
12d304f
to
37fceb7
Compare
37fceb7
to
fb7261d
Compare
@goerz Just saw you picked up work on this, thanks a lot! After our discussion in #2462 I decided to "fully qualify" all inter-module refs (using the full ref path instead of relative refs), downgrade errors to warnings and live with the messy build output. With the changes from your branch I can build the docs and the links in the resulting HTML all seem to work! Unfortunately I can't share the code here (it's private...), but I'll happily test any additional changes, if any. |
You can play around with https://github.com/goerz/DocumenterResolveXRefInMainPrototype.jl, which is this a packaged version of this PR, so I can test it "in the wild" more easily. This will take more work, though, because it seems like
isn't quite right. The code in
is quite unclear. So I'm going to have to read the code more to really understand the current code, and how it interacts with this proposed PR, and then document that. That being said, this PR, respectively the packaged |
fb7261d
to
d7bee24
Compare
For the original case, doesn't
already just work? |
I would never have thought of that trick, but it does indeed work! So that just makes it a policy decision then, and I'm not quite sure what to push for. It might still be a good idea to decide that we always want to try resolving reference in So let me know that you think, and I'll either finish up this PR with a test, or make a new PR that just does some refactoring and adds documentation. The refactoring would change the internal function The decision is basically whether, in the documentation, we want to have the paragraph below with or without the crossed-out text:
That's basically what it boils down to from the user's perspective, even though the full behavior is quite complicated (see my notes from diving into this) If we decide to stick to the current behavior (and then we should add a "tip" about
instead of just But we'll see… either decision works for me! |
Just my personal opinion, as a person that isn't primarily a Julia developer, in case anyone cares: I think that @goerz proposal is good to have from a user perspective and I'd vote for that, so to speak. Most other languages I've written extensive documentation for so far seem to have a mechanism that resolves "full" references. Having to prepend |
Hmm. I am not sure we want to encourage referencing objects just because they are available That said, being able to easily reference stuff outside the current module seems also quite reasonable, and having to prepend I.e. the logic would be that you first do the current logic, where you search from the current module, and then if that fails, you try to see if the reference is a This should mean that references like
and
would work, satisfying
But you would not be able to refer to objects just because they are in |
I agree: we should restrict the fallback to
Repeating the "current logic" but with I added this fix in the latest commit. I still have to add a test and changelog entry before this is ready to go. |
For any `@ref` link in a docstring to a code object, Documenter currently tries to find a binding for the code in the module where the docstring is defined. This often requires importing symbols only because they appear in a `@ref`. In some cases, this is not even possible, as it would create circular references. With this change, Documenter now tries to find binding for `@ref` links in docstrings first in the local module, and then in `Main`, which is basically `docs/make.jl`. Thus, anything imported in `docs/make.jl` can be referenced anywhere.
2d1a2a7
to
997619a
Compare
@mortenpi I finally got around to adding the test and changelog. This should be ready to merge now. As discussed, the fallback resolution to This PR should also make the error messages when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just a couple of phrasing suggestions -- feel free to take them or leave them, and then merge.
I can't comment on the code-side of things, but IMO the new docs along with the examples suggested by @mortenpi make it very clear what's supported and how it works. |
Co-authored-by: Morten Piibeleht <[email protected]>
Co-authored-by: Morten Piibeleht <[email protected]>
Co-authored-by: Morten Piibeleht <[email protected]>
For any
@ref
link in a docstring to a code object, Documenter currently tries to find a binding for the code in the module where the docstring is defined. This often requires importing symbols only because they appear in a@ref
. In some cases, this is not even possible, as it would create circular references. See also the very eloquent description in #2462 (comment)With this change, Documenter now tries to find binding for
@ref
links in docstrings first in the local module, and then inMain
, which is basicallydocs/make.jl
. Thus, anything imported indocs/make.jl
can be referenced anywhere.Closes #2462