Skip to content
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

rustdoc doc(cfg) rendering gets ugly with long cfg expressions #87957

Closed
jplatte opened this issue Aug 12, 2021 · 9 comments · Fixed by #113285
Closed

rustdoc doc(cfg) rendering gets ugly with long cfg expressions #87957

jplatte opened this issue Aug 12, 2021 · 9 comments · Fixed by #113285
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Aug 12, 2021

I think long cfg expressions should be broken across multiple lines. I saw this cause issues here:

Screenshot_2021-08-12_120327

@jplatte jplatte added the C-bug Category: This is a bug. label Aug 12, 2021
@jyn514 jyn514 added A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. and removed C-bug Category: This is a bug. labels Aug 16, 2021
@GuillaumeGomez
Copy link
Member

Do you have an idea on how to improve this maybe @dns2utf8 @jsha?

@dns2utf8
Copy link
Contributor

What if we inserted zero width spaces after the keywords? So after each or we insert a zero width space U+200B (see the example in my blog).
Maybe we would have to wrap each name in a span too but I would have to experiment a bit.
Then each expression would try to stay as an inline-block and then break the line on the keywords (like and, or, not, ...)

@GuillaumeGomez
Copy link
Member

If we start having "groups", not sure if it'll work well. But definitely worth a try!

@dns2utf8
Copy link
Contributor

I started a test case with a long and complicated expression that results in this image:

#[cfg(any(feature="long-feature-flag-name",feature="appservice-api", not(feature="clientservice-c"), all(feature="clientservice-rust",feature="identity-clientservice-embedded-something-something-i-need-something-long-to-testing")))]
#[no_mangle]
/// This is a function that requires a lot of flags
pub fn rarely_used_function() {}

grafik

Currently combining a lot of short features is very unreadable and not's are hard to spot.

With just span code { display: block; } it gets a lot more readable, but since the braces get lost in translation it is not clear which flags are binding with or, not or and respectively.
grafik

What if we display a little tree diagram? For most cases that would probably result in a short list with an and or an or in the beginning.

Another idea could be to not draw the tree but to have visible boxes encasing the respective flags.
What do you think?

@GuillaumeGomez
Copy link
Member

I need to see things to be able to make my own opinion on which approach is better. 😄 But maybe @jsha has an idea?

@jhpratt
Copy link
Member

jhpratt commented Nov 13, 2021

Maybe it could show "any of"/"all of" on longer chains (say 3+)? I don't think there's a ton that can realistically be done here — a long cfg is going to result in a long doc cfg.

@GuillaumeGomez
Copy link
Member

There are a lot of things that can be done. For example, for more than 3 items, we could show only the 3 first and show the rest on click. It's mostly about how to display things.

@jplatte
Copy link
Contributor Author

jplatte commented Jan 2, 2022

The original case has gotten a lot better, the actual doc string now gets ~60% of the horizontal space rather than ~30%:

Screenshot_2022-01-02_202521

@jplatte
Copy link
Contributor Author

jplatte commented Mar 12, 2023

Rendering has degraded again (even though the documented cfg expressions themselves have become shorter):

Screenshot 2023-03-12 at 16-10-41 ruma api - Rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. F-doc_cfg `#![feature(doc_cfg)]` requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants