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

Open impl blocks by default #84552

Merged
merged 6 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ function hideThemeButtonState() {
}
// Open all ancestor <details> to make this element visible.
openParentDetails(h3.parentNode);
} else {
openParentDetails(elem.parentNode);
}
}
}
Expand Down Expand Up @@ -1422,11 +1424,13 @@ function hideThemeButtonState() {
// errors in mobile browsers).
if (e.tagName === "H2" || e.tagName === "H3") {
var nextTagName = e.nextElementSibling.tagName;
if (nextTagName == "H2" || nextTagName == "H3") {
if (nextTagName === "H2" || nextTagName === "H3") {
e.nextElementSibling.style.display = "flex";
} else {
} else if (nextTagName !== "DETAILS") {
e.nextElementSibling.style.display = "block";
}
} else if (e.tagName === "DETAILS") {
e.open = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand it, we hide things during load because we're going to manipulate their DOM, and DOM manipulation on hidden things goes faster. The main DOM manipulation is adding the [+] toggles. When we fully switch over to <details> we won't need to hide portions of the DOM during load anymore.

I'd like to start doing that as we go. Rather than opening the <details> tags on load, we should set them to the global default in our generated HTML, and on load we should hide or show them according to settings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not all details should be opened by details. For example the traits implementations blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or did you mean that we should generate the <details> with "open" directly? Still: we will need this JS in any case for when we press the global toggle.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I mean that for default-shown sections we should generate <details open>.

I agree we need JS to make <details> respond to the global toggle, but I believe that's already in place. And it wouldn't be in this chunk of code, which executes on load rather than in response to the global toggle.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I'll modify it then.

}
});
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc-gui/hash-item-expansion.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This test ensures that the element corresponding to the hash is displayed.
goto: file://|DOC_PATH|/struct.Foo.html#method.borrow
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
// a class selector.
assert: ("#method\.borrow", {"display": "flex"})
// We first check that the impl block is open by default.
assert: ("#implementations + details", "open", "")
// We collapse it.
click: "#implementations + details > summary"
// We check that it was collapsed as expected.
assert-false: ("#implementations + details", "open", "")
// To ensure that we will click on the currently hidden method.
assert: (".sidebar-links > a", "must_use")
click: ".sidebar-links > a"
// We check that the impl block was opened as expected so that we can see the method.
assert: ("#implementations + details", "open", "")
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/impl-default-expansion.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This test ensures that the impl blocks are open by default.
goto: file://|DOC_PATH|/struct.Foo.html
assert: ("#main > details.implementors-toggle", "open", "")
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that intentionally fails to make sure this runs at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are not run, that's for sure. Otherwise, it'd have failed a long time ago because of nojs-attr-pos.goml.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. In the meantime, can you run it locally and make sure it passes?

Copy link
Member Author

Choose a reason for hiding this comment

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

This version didn't because I forgot to commit the one with the correct URL (struct.Foo.html and not index.html). But otherwise it works as expected.

Copy link
Member

@jyn514 jyn514 Apr 25, 2021

Choose a reason for hiding this comment

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

Can you fix it to have the correct URL? I don't see the point of adding a test we know will fail.

While you're at it, can you update the other test to pass instead of removing it altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

Look at my comment below.

Copy link
Member Author

Choose a reason for hiding this comment

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

While you're at it, can you update the other test to pass instead of removing it altogether?

The test which fails checked for attributes toggles. Since they don't have toggles anymore, there is no point of keeping the test.

Copy link
Member

Choose a reason for hiding this comment

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

The test which fails checked for attributes toggles. Since they don't have toggles anymore, there is no point of keeping the test.

Can you instead test that it doesn't have toggles?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be useful to check that something was removed? For example, if we put back toggles on attributes with a different DOM, the test would still be happy. Which is why it's simpler to enforce what exists over what doesn't. (Not sure if that makes sense said like this ><)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @GuillaumeGomez. When removing "code that does X," it's often tempting to add a test for "doesn't do X anymore." But the problem is there are a zillion ways it could wind up doing X again, and it's impossible to cover all of them (or even a reasonable fraction). It winds up adding to the test running time, and the burden of maintaining tests, without a corresponding benefit.

5 changes: 0 additions & 5 deletions src/test/rustdoc-gui/nojs-attr-pos.goml

This file was deleted.