-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: Call initSidebarItems
in root module of crate
#85304
Conversation
9545f7a
to
2203840
Compare
src/librustdoc/html/render/mod.rs
Outdated
if parentlen == 0 { | ||
// There is no sidebar-items.js beyond the crate root path | ||
// FIXME maybe dynamic crate loading can be merged here | ||
write!(buffer, "<script defer src=\"top-level-sidebar-items.js\"></script>",); | ||
} else { | ||
write!(buffer, "<script defer src=\"{path}sidebar-items.js\"></script>", path = relpath); | ||
} |
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.
I think what we really want here, rather than generating a file with a different name, is to generate a file named sidebar-items.js
in the doc root, and unconditionally write a script tag that loads it. So these two if
branches would get collapsed into one.
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.
That's better yeah
let js_dst = self.dst.join("sidebar-items.js"); | ||
let v = format!("initSidebarItems({});", serde_json::to_string(&items).unwrap()); | ||
scx.fs.write(&js_dst, &v)?; | ||
|
||
let js_dst = self.dst.join("top-level-sidebar-items.js"); | ||
scx.fs.write(&js_dst, "initSidebarItems({});")?; |
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.
I'm a little confused... reading the code above this: if the added code works to add a file at the top level, there should already be a sidebar-items.js at the top level.
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.
the top-level
does not mean the top-level of the generated documentation, but is just an alternative name to distinguish between initSidebarItems({})
and initSidebarItems({ /* some items */})
Specifically by "top level" I'm thinking of e.g. https://doc.rust-lang.org/std/. But I'm now realizing there's also a per-module index.html that we need to fix up, and that's what you've fixed up so far. Am I on the right track here? And we need to generate a separate top-level-sidebar-items.js because for the per-module index.html, we specifically don't want to list all the extra stuff that's in the real sidebar-items.js? |
No, the I think the new |
I pushed the changes that I meant in my last message. Maybe that helps to understand. |
This is looking good! But when I build locally and visit file:///home/jsha/rust/rust/build/x86_64-unknown-linux-gnu/doc/std/index.html, I get a JS console error:
And indeed that file doesn't exist. But |
Does |
Apparently, it does. Should the file just be written as an unversichert file or adjust the script tag to include the version? |
It needs the version number if it's a cross-crate shared file (mostly for docs.rs and doc.rust-lang.org purposes). |
Ah, that makes sense. Do you think the |
Strangely, your fix looks very different than the one I wrote in 4e22b32 |
I think sidebar-items.js should not have a version number at the crate root, because it doesn't have a version number in other places, and it would confusing. @GuillaumeGomez sorry I didn't realize there was already a fix in progress. I think we should plan on landing this one to fix the regression since it's much smaller. |
Looks good to me in a local test. Thanks for working so quickly to fix. @bors r+ |
📌 Commit b8c546862c4277b2a3259f662dda712626c2e9b0 has been approved by |
If it's going to be unversioned, then it needs to be not in the shared files, otherwise docs.rs will have issues if the JS API ever changes. docs.rs can handle unversioned unshared files at the root of the doc-folder now, |
This comment has been minimized.
This comment has been minimized.
@bors r- |
Alright. Then I will just revert my last commit! |
b8c5468
to
7c4f3f4
Compare
I messed up the rebase. Whoops |
It does not add a new file at every module 🤔 |
This approach adds a single new shared file, not even per-crate. This seems by far the simplest minimal change I can see to get backported onto beta to fix it there. It may be possible to simplify it as part of #84834 or other fixes in nightly, but we need to get something that can be backported first. |
I can make #84834 much shorter by only putting back the crate list if you want in another PR. But I'm strongly against adding a new unneeded file. |
I can also change this PR to use another fix. I just thought this is an easy way to call the |
@Stupremee: Sorry that you're in the middle of this. :-/ I should have included @jsha on my other PR's discussion, that would have prevented all the problems in here... |
The only way I can see to do this without a new file (or some more major refactoring of how Testing #84834 locally it has an additional change in behaviour that it shows children instead of siblings in the sidebar, that is how it manages to not add a new file because it looks one level deeper on all module's sidebars. |
Yes, this is what I said, I have two changes in my PR. I can extract the fix for the crate listing in another PR to keep the one under debate if you want. |
No problem!
That works too and might be the fastest solution. |
We discussed on discord and decided to go ahead with this as a first fix. @bors r+ |
📌 Commit aaf0ff8 has been approved by |
☀️ Test successful - checks-actions |
…ulacrum [beta] backports * Backport 1.52.1 release notes rust-lang#85404 * remove InPlaceIterable marker from Peekable due to unsoundness rust-lang#85340 * rustdoc: Call initSidebarItems in root module of crate rust-lang#85304 * Update LLVM submodule rust-lang#85236 * Do not ICE on invalid const param rust-lang#84913 * Disallows #![feature(no_coverage)] on stable and beta (using standard crate-level gating) rust-lang#84871 * Ensure TLS destructors run before thread joins in SGX rust-lang#84409
r? @jsha
Resolves #85301