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 options to set default theme (and other settings) #77213

Merged
merged 7 commits into from
Oct 29, 2020

Conversation

ijackson
Copy link
Contributor

@ijackson ijackson commented Sep 26, 2020

Hi. This is the MR I promised in #77024

It is a little more general than I envisaged there. Once I had found the settings-handling machinery it seemed foolish to add this feature just for the theme.

Closes #77024

@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 26, 2020
@ollie27 ollie27 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 26, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 13, 2020

ping @GuillaumeGomez

@camelid camelid added A-rustdoc-themes Area: Themes for HTML pages generated by rustdoc A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Oct 13, 2020
@GuillaumeGomez
Copy link
Member

You added the getSettingValue and replaced a few setting getters, but could you replace all of them please?

@ijackson ijackson force-pushed the wip-rustdoc-settings branch from c50bb7b to ab195aa Compare October 13, 2020 18:25
@ijackson
Copy link
Contributor Author

Hi. Thanks for the review. I have made those changes. I rebased onto current master, and then made the requested changes as new commits, for ease of your review (and as requested by the highfive bot). I did them as git autosquash, and when you're happy with the series, will squash it down.

@bors
Copy link
Contributor

bors commented Oct 16, 2020

☔ The latest upstream changes (presumably #77809) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@ijackson
Copy link
Contributor Author

You added the getSettingValue and replaced a few setting getters, but could you replace all of them please?

As requested, I did this. Unfortunately it didn't get a review before some other changes went in which conflicted. By its nature, the change to use getSettingValue everywhere is very textually intrusive and likely to break. If I rebase and fix the merge conflicts, will I get a prompt review?

(FTR obviously I approve of #77809 and it should work well in combination with my work in this MR.)

@jyn514
Copy link
Member

jyn514 commented Oct 23, 2020

@ijackson is this PR still needed after #77809 ? It seems like #77024 should be fixed by setting your system theme to the default that you want.

@ijackson
Copy link
Contributor Author

ijackson commented Oct 23, 2020 via email

@GuillaumeGomez
Copy link
Member

Please rebase to fix merge conflicts then ping me and I'll review again (but it seems mostly good already).

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2020
Currently, storage.js and main.js have many open-coded calls to
getCurrentValue for "rustdoc-" values, but these are settings and
should be handled by getSettingValue.

So make getSettingValue part of storage.js (where everyone can call
it) and use it everywhere.

No functional change yet.  We are going to make getSettingValue do
something more sophisticated in a moment.

Signed-off-by: Ian Jackson <[email protected]>
rustdoc has various user-configurable preferences.  These are recorded
in web Local Storage (where available).  But we want to provide a way
to configure the default default, including for when web storage is
not available.

getSettingValue is the function responsible for looking up these
settings.  Here we make it fall back some in-DOM data, which
ultimately comes from RenderOptions.default_settings.

Using HTML data atrtributes is fairly convenient here, dsspite the
need to transform between snake and kebab case to avoid the DOM
converting kebab case to camel case (!)

We cache the element and dataset lookup in a global variable, to
ensure that getSettingValue remains fast.

The DOM representation has to be in an element which precedes the
inclusion of storage.js.  That means it has to be in the <head> and we
should not use an empty <div> as the container (although most browsers
will accept that).  An empty <script> element provides a convenient
and harmless container object.  <meta> would be another possibility
but runs a greater risk of having unwanted behaviours on weird
browsers.

We trust the RenderOptions not to contain unhelpful setting names,
which don't fit nicely into an HTML attribute.  It's awkward to quote
dataset keys.

Signed-off-by: Ian Jackson <[email protected]>
We just plumb through what the user tells us.

This is flagged as unstable, mostly because I don't understand the
compatibility rules that rustdoc obeys for local storage data, and how
error handling of invalid data works.

We collect() the needed HashMap from Vec of Vecs of (key, value)
pairs, so that there is a nice place to add new more-specific options.
It would have been possible to use Extend::extend but doing it this
way ensures that all the used inputs are (and will stay) right next to
each other.

Signed-off-by: Ian Jackson <[email protected]>
This is a fairly simple special case of --default-eetting.  We must
set both "theme" and "use-system-theme".

Providing it separately enables us to document a way to set the theme
without expoosing the individual settings keywords, which are quite
complex.

Signed-off-by: Ian Jackson <[email protected]>
@ijackson ijackson force-pushed the wip-rustdoc-settings branch from ab195aa to 709efd9 Compare October 28, 2020 18:05
@ijackson
Copy link
Contributor Author

@GuillaumeGomez

Please rebase to fix merge conflicts then ping me and I'll review again (but it seems mostly good already).

Now done, thanks. I made some slight improvements to the Rust parts so you may want to re-review them.

@GuillaumeGomez
Copy link
Member

Just nits on my end. Maybe you want to take a last look @jyn514 too?

@ijackson
Copy link
Contributor Author

ijackson commented Oct 28, 2020 via email

@GuillaumeGomez
Copy link
Member

In this case it's fine, you're still under the "rebase bar". :p Just push another commit to fix the nits.

* Remove a needless comma in the Rust code
* Replace double spaces after full stops with single spaces

Requested-by: @GuillaumeGomez
Signed-off-by: Ian Jackson <[email protected]>
@ijackson
Copy link
Contributor Author

@GuillaumeGomez Done, thanks.

@GuillaumeGomez
Copy link
Member

All good for me. Just a last check from @jyn514 and then it's good to go!

Comment on lines +272 to +281
unstable("default-theme", |o| {
o.optopt(
"",
"default-theme",
"Set the default theme. THEME should be the theme name, generally lowercase. \
If an unknown default theme is specified, the builtin default is used. \
The set of themes, and the rustdoc built-in default is not stable.",
"THEME",
)
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is default-theme special cased? If you want default-settings to work for arbitrary settings, I think it makes sense to use it for themes too. If you want this to be documented, I would rather document settings in the unstable section of the rustdoc book (src/doc/rustdoc/src/unstable-features.md).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I would also be ok with getting rid of default-settings and only keeping default-themes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage names are rather internal, and --default-setting sets them directly. That's good for flexibility but it is rather too raw.

Indeed, as you can see from the implementation, --default-theme doesn't just set the theme setting. Because of the way the "use system theme" option and the light/dark themes operate, since #77809, it is necessary to change the default for "use system theme" to "false" for the --default-theme option to work.

Indeed, I think this fact about #77809 shows that my pre-#77809 approach of having a raw --default-setting option, and a cooked --default-theme option, was correct. Before #77809, --default-theme just set the theme setting. Now it does more.

Notice that the stability caveats for the two options are rather different. Another aspect of this is that it might easily make sense to stabilise the --default-theme option soon, after we've had some experience with it. Stabilising the raw --default-setting option would involve thinking about what additional promises that would imply (maybe none that we care about? but I'm not sure and it's certainly harder to think about)

.flatten()
.collect(),
matches
.opt_strs("default-setting")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing that --default-theme breaks is you now have different behavior for --default-theme x and --default-setting theme=x - the first will set use-system-theme=false, the second will not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is inevitable and deliberate. As you can see from the usage message we do not make any promises about the particular behaviour of --default-setting. The available settings and their semantics and not documented and not stable.

Whereas the semantics of --default-theme are well-defined, and are implemented by setting the two internal settings.

I do think it is worth keeping --default-setting even despite these caveats because in practice the storage settings are visible to users via their browser and of course if they look at the JS.

The difference between --default-setting and --default-theme is like the difference between firefox's about:config and about:preferences.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my question is why you would ever want to modify default-setting. All those settings are also configurable on a per-user basis on settings.html - do we really need so much flexibility as to make the 'default defaults' configurable too?

src/librustdoc/config.rs Show resolved Hide resolved
src/librustdoc/config.rs Outdated Show resolved Hide resolved
ijackson and others added 2 commits October 28, 2020 21:25
This allows removing a `mut` which is nicer.

Suggested-by: @jyn514
Signed-off-by: Ian Jackson <[email protected]>
@ijackson
Copy link
Contributor Author

ijackson commented Oct 28, 2020 via email

@jyn514
Copy link
Member

jyn514 commented Oct 28, 2020

@bors r=jyn514,GuillaumeGomez

In practice I don't expect --default-settings to be used often, but since it's perma-unstable I'm ok with adding it. --default-theme definitely seems like a good improvement.

@bors
Copy link
Contributor

bors commented Oct 28, 2020

📌 Commit 776e204 has been approved by jyn514,GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 28, 2020
@ijackson
Copy link
Contributor Author

ijackson commented Oct 28, 2020 via email

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 29, 2020
Rollup of 11 pull requests

Successful merges:

 - rust-lang#77213 (rustdoc options to set default theme (and other settings))
 - rust-lang#78224 (min_const_generics: allow ty param in repeat expr)
 - rust-lang#78428 (MinConstGenerics UI test for invalid values for bool & char)
 - rust-lang#78460 (Adjust turbofish help message for const generics)
 - rust-lang#78470 (Clean up intra-doc links in `std::path`)
 - rust-lang#78475 (fix a comment in validity check)
 - rust-lang#78478 (Add const generics tests for supertraits + dyn traits.)
 - rust-lang#78487 (Fix typo "compiltest")
 - rust-lang#78491 (Inline NonZeroN::from(n))
 - rust-lang#78492 (Update books)
 - rust-lang#78494 (Fix typos)

Failed merges:

r? `@ghost`
@bors bors merged commit 2008d1b into rust-lang:master Oct 29, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 29, 2020
@ijackson ijackson deleted the wip-rustdoc-settings branch October 29, 2020 11:04
ijackson added a commit to ijackson/rust that referenced this pull request Dec 2, 2020
As discussed in rust-lang#77213, this seems like it has bedded in and can be
safely and usefully made stable.

(rustdoc already has other stable options that interact quite
intimately with the rustdoc-supplied CSS, and also an option for
supplying entirely different CSS, so exposing the theme names this way
seems a very minor step.)

Signed-off-by: Ian Jackson <[email protected]>
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 27, 2020
rustdoc: stabilise --default-theme command line option

As discussed in rust-lang#77213, this seems like it has bedded in and can be safely and usefully made stable.

(rustdoc already has other stable options that interact quite intimately with the rustdoc-supplied CSS, and also an option for supplying entirely different CSS, so exposing the theme names this way seems a very minor step.)

There is also a commit to do some minor grammar fixes to the help message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-themes Area: Themes for HTML pages generated by rustdoc A-rustdoc-ui Area: Rustdoc UI (generated HTML) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc: Please provide way to set the default theme
8 participants