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: change .src-line-numbers > span to .src-line-numbers > a #103650

Merged
merged 3 commits into from
Nov 13, 2022

Conversation

notriddle
Copy link
Contributor

Example: https://notriddle.com/notriddle-rustdoc-demos/line-anchors/test_dingus/fn.test.html

This allows people to treat them like real links, such as right-click to copy URL, and makes the line numbers in a scraped example work at all, when before this commit was added, they had the clickable pointer cursor but did not actually do anything when clicked.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 27, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2022

A change occurred in the Ayu theme.

cc @Cldfire

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @Folyd, @jsha

Some changes occurred in HTML/CSS themes.

cc @GuillaumeGomez

@notriddle notriddle force-pushed the notriddle/line-anchors branch 4 times, most recently from 5f38053 to 563986e Compare October 27, 2022 19:07
@GuillaumeGomez
Copy link
Member

With this change, when another line is selected, the original one keeps the right border:

image

Just to explain a bit more what I did:

  1. Click on a example line number.
  2. When on the source code page, click on another line.
  3. The border of the "original" line is still orange.

When switched back to <span>, it doesn't keep it, so I suppose it's a new bug. Once fixed, can you add a test to ensure that it doesn't happen please?

@notriddle notriddle force-pushed the notriddle/line-anchors branch 2 times, most recently from d9b9630 to c9e7c56 Compare October 28, 2022 17:24
@@ -211,6 +216,12 @@ const handleSourceHighlight = (function() {
};
}());

const addSourceLineAnchorsHref = () => {
onEachLazy(document.querySelectorAll(".src-line-numbers a"), e => {
Copy link
Member

Choose a reason for hiding this comment

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

This is unneeded. If there is an ID, it automatically links to itself if there is no href.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it? When I try running with this function patched out, clicking the links still works, but right-clicking them doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

What is the right clicking supposed to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's supposed to let me copy a link to the clipboard, or open it in a new tab.

image

Copy link
Member

Choose a reason for hiding this comment

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

Oh indeed. It doesn't propose to copy a link, what a shame... Then I guess it comes to this: is it better to generate href through JS or in the HTML directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it really depends on how much bigger it makes the doc bundle. If it's only 1% or so, it's probably fine to just use HTML. If it's more like 10%, it should probably be JavaScript, or skip this PR entirely.

Copy link
Member

Choose a reason for hiding this comment

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

Let's see once we have results to think about. ;)


const addSourceLineAnchorsHref = () => {
onEachLazy(document.querySelectorAll(".src-line-numbers a"), e => {
e.href = linkPage + "#" + e.innerText;
Copy link
Member

Choose a reason for hiding this comment

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

On small pages, it's fine. However, it's a very bad ideas as soon as you start to have more than 5 functions with examples which comes pretty quickly. Either generate directly the URLs (which would increase the size) or don't change it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense.

Okay, I've changed it to just embed the links directly in the outputted HTML.

Copy link
Member

Choose a reason for hiding this comment

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

Big question: is it worth it? It'll increase the page size quite a lot.

@notriddle
Copy link
Contributor Author

Let’s see how much, I suppose.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2022
@bors
Copy link
Contributor

bors commented Oct 29, 2022

⌛ Trying commit ec5181653e19477b01f2f1eb60db969c3598b36d with merge c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f...

@bors
Copy link
Contributor

bors commented Oct 29, 2022

☀️ Try build successful - checks-actions
Build commit: c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f (c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f)

@rust-timer
Copy link
Collaborator

Queued c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f with parent 33b530e, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.0% [0.4%, 1.4%] 3
Regressions ❌
(secondary)
1.8% [0.4%, 4.1%] 16
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.0% [0.4%, 1.4%] 3

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.1%, 2.8%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 29, 2022
@notriddle
Copy link
Contributor Author

doc-bytes results: https://perf.rust-lang.org/compare.html?start=33b530e04099465a8029ef581202d52f4075558e&end=c02fcd308362e1b1a08a8c1ba40eaffb84e1d23f&stat=size%3Adoc_bytes

mean range count
Regressions ❌
(primary)
1.66% [0.23%, 4.14%] 17
Regressions ❌
(secondary)
1.05% [0.01%, 6.75%] 22
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.66% [0.23%, 4.14%] 17

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 29, 2022
…e-css, r=notriddle

Fix z-indexes of code example feature and cleanup its CSS

When reviewing rust-lang#103650, I realized that the `z-index`es of this feature were completely broken:

![Screenshot from 2022-10-28 10-55-27](https://user-images.githubusercontent.com/3050060/198826360-0c5cbe5a-ea8e-452a-9504-38d3da3615e6.png)

This PR fixes it by reducing the value of value under the one used for `.popover` (it could be completely removed but then it wouldn't be displayed as nicely).

There was also a lot of duplicated CSS so I merged the rules.

r? `@notriddle`
@GuillaumeGomez
Copy link
Member

I think it's acceptable. r=me once you have fixed the merge conflict.

@notriddle
Copy link
Contributor Author

@GuillaumeGomez Okay, it's rebased.

writeln!(line_numbers, "<span>{0}</span>", line + offset)
for line_number in 1..=lines {
let line = line_number + offset;
writeln!(line_numbers, "<a href=\"{root_path}{url}#{line}\">{line}</a>")
Copy link
Member

Choose a reason for hiding this comment

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

This one is still bugging me: as soon as this feature is enabled by default, the size will increase like crazy... I'm really not sure it's worth it to generate links here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would generating it with JavaScript be better?

Copy link
Member

Choose a reason for hiding this comment

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

No because then it would become a performance problem on the front-end side. Maybe I'm just overthinking things in here... The problem is that this feature has basically no test or anything, so it's really not great.

Maybe let's ask what the @rust-lang/rustdoc team thinks about it?

Copy link
Member

Choose a reason for hiding this comment

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

I assume the doc_bytes benchmarks are raw file sizes? Seems like this should compress really well and not affect the transferred size much.

Copy link
Member

Choose a reason for hiding this comment

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

The problem isn't the network part of the GUI rendering.

@rust-log-analyzer

This comment has been minimized.

This allows people to treat them like real links, such as right-click to
copy URL, and makes the line numbers in a scraped example work at all,
when before this commit was added, they had the clickable pointer cursor
but did not actually do anything when clicked.
@notriddle
Copy link
Contributor Author

I can't think of any way to really mitigate the HTML overhead. Is this worth rebasing? Or just call it a dud and submit the :target fix as a separate PR?

@GuillaumeGomez
Copy link
Member

Then I suggest this: let's only keep this change for the source code pages and remove it for the examples as it is where it will crazily increase.

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 12, 2022

📌 Commit cb3a04b has been approved by GuillaumeGomez

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2022
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 12, 2022
…r=GuillaumeGomez

rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a`

Example: https://notriddle.com/notriddle-rustdoc-demos/line-anchors/test_dingus/fn.test.html

This allows people to treat them like real links, such as right-click to copy URL, and makes the line numbers in a scraped example work at all, when before this commit was added, they had the clickable pointer cursor but did not actually do anything when clicked.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 13, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#103650 (rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a`)
 - rust-lang#104177 (rustdoc: use consistent "popover" styling for notable traits)
 - rust-lang#104318 (Move tests)
 - rust-lang#104323 (rustdoc: remove no-op CSS `.scrape-help { background: transparent }`)
 - rust-lang#104345 (Fix up a Fluent message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 96753eb into rust-lang:master Nov 13, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 13, 2022
@notriddle notriddle deleted the notriddle/line-anchors branch November 13, 2022 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.

7 participants