-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rustdoc: add links to online source files if "url" attribute is present in crate #2072
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
Comments
Alternatively, we could establish a new convention where the URL attribute must actually point at the crate file, rather than just at the page where a link to the crate file exists. |
I'm not really sure what the purpose of the link url attribute is supposed to be, but we can probably come up with some heuristics to find a reasonable link based on a github url and the local directory structure. Possibly we can override it with |
This is implemented a bit naively in rustdoc_ng, although it still needs a bunch of polish. @catamorphism what rustpkg integration would this involve? |
It might be better for rustdoc to actually package up the source itself, parallel to the actual docs, rather than link to some other online source:
This could even be inline in a page, so one can click-to-expand the function body (for example). (Prompted by Ygg2 on HN.) (cc @alexcrichton) |
+1 << N (for quite high values of N) for including the source, for the same reasons. My first inclination was "keep the size down by doing highlighting in JavaScript", but then I realised that we can do it better otherwise (JavaScript could still be used if desired which could lead to smaller files; the advisability of that can be considered later); we could even annotate it with cross-references to and fro, hither and yon, making it really useful. Bear in mind, however, that it is possible that someone may not wish to reveal the source if they are writing a closed-source crate but still want docs. When this is implemented, the driver should have a flag added to disable it. |
I for one would prefer links to github if that is available, because the source can't change if you link to the proper commit and not master, and because you get the full file at least, so you can browse around a bit as well. That is, if you thought of embedding the entire source and a source browser and then linking to that, fine by me, but if it's just embedding the few lines relating to the function/struct/.. at hand, I think that's less powerful than github links. |
Yeah if you store everything as I said that's cool as well but it's a lot more work than just linking to github for now :) |
With Rails, we do both: http://api.rubyonrails.org/classes/ActionDispatch/Request.html (pick any method. there's an 'code' and a 'link to github' both.) |
I definitely agree that we should include the source in the page somehow, whether it's on github or just the source file itself. I'm actually quite in favor of including the source manually for the exact reason of version drift. I doing something like rustfind would also be awesome, but it's probably not necessary right from the get-go. I'd like to add support for github source links, but right now I don't trust our versioning capabilities to be able to do that. In the meantime, I will make it such that we at least render the source in some manner to the documentation directories and then we can always link into them. |
Python does this for a few of its stdlib docs, as seen here: http://docs.python.org/py3k/library/socketserver.html
It would be pretty neat if Rustdoc could do this automatically by leveraging the metadata in the project's crate. To start, this would work easily for std:
By taking the URL and appending the name of each source file you get valid pages:
https://github.com/mozilla/rust/tree/master/src/libstd/arena.rs
https://github.com/mozilla/rust/tree/master/src/libstd/bitv.rs
It's a bit more difficult for projects where the crate file is in the root directory:
Note the difference between the naively appended URL and the true URL:
https://github.com/alegalle/rust_glfw/glfw.rs
https://github.com/alegalle/rust_glfw/blob/master/glfw.rs
Even if it means adding some Github-specific code, I think it would be worth it (especially since Github seems to be our "blessed" platform, and since rust_glfw registers the same URL with cargo-central, so Cargo must already be applying this transformation).
The text was updated successfully, but these errors were encountered: