-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Better listing of dependencies in 'cargo docs' sidebar output #81031
Comments
Transferred to rust-lang/rust, as this issue is about rustdoc and its issues are tracked here. |
I agree we should fix this. If you want to go to the root of the current crate, you can always click on the crate name on the item you're looking at.
I'm not opposed to this, but it's the sort of change that only happens if someone volunteers to put in the time. I'm happy to help mentor if you want to work on it. |
This sounds like a pretty interesting project to work on. It may take a while for me to do this but luckily this doesn't seem like an issue that is very critical, to be honest (Though I may split it into two parts: fixing that first issue about the rust logo, and possibly prioritizing packages in the sidebar). Wish me luck! |
As for sidebar reordering, I'm thinking something like this could be helpful:
(maybe in their own sections? idk) |
I need that feature, so I'm willing to help (depending on the time needed: how long would it take?). At least, I think that the workspace crates should be separated from the dependencies to emphasize the content of the project. |
I don't know; most of rustdoc is frankly not very good code, it's very interconnected and small changes in one area can have unexpected side effects. I'd suggest writing your change then seeing if the tests fail. I no longer have time to mentor this, but @GuillaumeGomez or @jsha may. |
Sorry, missed this issue. There is a work in progress already in #84834. Once this one is merged, you can try changing what you have in mind? |
@GuillaumeGomez I'm not sure how that PR is related? It affects where the sidebar is displayed but not the contents. |
It heavily affects the sidebar content. ;) |
Eheh, I have a bad feeling about this 😅
You can ping me when I can implement this change. |
Subscribe to the PR then, I'm about to send an update there. :) |
@dbr for your use case, do you need the less-important docs to still be generated (but hidden)? Or would it be acceptable for them to not be generated at all? Currently
Perhaps a good solution for your use case would be a flag like |
I looked a little at fixing this (I agree, this should work!), and ran into some issues. As I understand it, when you run Also,
When the index page is present, clicking the logo should take you to the index page, rather than the "main" crate. I'm not sure if One somewhat hacky approach would be: The logo points to |
It can if you use |
As a workaround, it's quite straightforward to automate purging non-workspace crates from the documentation: python -c 'import tomllib; from pathlib import Path; m = [c.replace("-", "_") for c in tomllib.load(Path("Cargo.toml").open("rb"))["workspace"]["members"]]; Path("target/doc/crates.js").write_text(f"window.ALL_CRATES = {m};")' Makefile: removemembers = python -c \
'import tomllib ;\
from pathlib import Path ;\
m = [ \
c.replace("-", "_") \
for c in tomllib.load(Path("Cargo.toml").open("rb"))["workspace"]["members"] \
] ;\
Path("target/doc/crates.js").write_text(f"window.ALL_CRATES = {m};")'
.PHONY: doc
doc:
cargo doc --lib --bins
$(call removemembers) |
Describe the problem you are trying to solve
In short: in the generated HTML docs, the sidebar list of dependencies isn't very useful in any project with many (tens or hundreds) of dependencies.
Longer:
In the
cargo docs
output for my application, there is a huge list of crates listed in the sidebar (around 200). Very few of these are interesting to me - a huge majority are indirect dependencies potentially 10+ levels deep, but they are presented in a flat listing.It's good these are documented, but listing them in the sidebar so prominently doesn't seem helpful to me, as almost all of the time I either want to:
Cargo.toml
)When you first open the docs (e.g
cargo docs --open
) it lists all my apps modules and so on. This is good.However if I want to find the docs for, say,
serde_json
, I have to scroll down the very long list (I could ctrl+f search, but at that point I might as well use the doc's nice search feature)Then, once you have clicked on a dependency, it's hard to directly navigate back to my application's docs (have to find
myapp
in the sidebar, or, search)Describe the solution you'd like
I think this has a two parts - I don't have strong opinions on the exact design etc, but the functionality I would find very useful are:
Always having a "single click" link back to the "main crate" (the one
cargo docs
was run for) in some waySay if I run
cargo docs --open
formyapp
, I would expect that there would be a link at the top of the sidebar which links back to./target/doc/myapp/index.html
.Currently, I would expect clicking the Rust logo at the top would go back here, but it goes to the index of the currently-clicked package docs
Prioritizing the packages in the sidebar somehow.
Some ideas for this might be:
cargo tree
. Might not work too well in the narrow side barreqwest
then only display that in sidebar - then if I click onreqwest
, then display the dependencies of that likehyper
etc)Cargo.toml
- ones which would appear more prominantly in the sidebar. Kind of like a "favourites"Notes
This idea only relates to the UI presentation of the sidebar, it wouldn't reduce the amount of documentation generated, and should be doable in a way which makes the big list of dependencies still available as it is surely valuable in some circumstances
Of the existing options there is a few which sort of help with this problem, not don't do what I'm hoping for:
cargo doc --no-deps
is too drastic, completely removes the dependencies.cargo doc --exclude
could kind of solve this (exclude everything except my top-level deps), but having the indirect dependencies available is still useful (particularly via search or links from return types etc etc), and this is very cumbersome to maintainThe text was updated successfully, but these errors were encountered: