-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Eliminate horizontal scrolling in rust code blocks #2012
Comments
Hi @1dimir, thanks for bringing this up!
Oh, good point! I've probably forgotten to update the width after we turned on the line numbers. You're completely right that we should not have code blocks with 1k lines in this course. The longest code blocks I know of are in 56.1. RTC Driver and related exercises. I think they're mostly there because @qwandor developed a tool which will generate zip files with the code blocks. I would prefer the code blocks to be removed from the pages (#625). I've wondered if we could implement something which will issue warnings or errors if it sees more than N lines of code on a single slide. @djmitche has been working on splitting up large slides together with @mani-chand (#1464).
Luckily, Please see the Formatting section for all the tools to install 😄 Let us know if this works/doesn't work for you! |
Hello @mgeisler , Could explain it bit in detail , You mean the code should not cross a specific number of lines. Can you specify how many lines you would like to have a playground. I would suggest if it crossed that specific number of lines we will display the redbox (#1842) as warning. We can use |
Ah, I had not thought of that. It could be interesting for local development. However, the warning/error I'm talking about here has to be generated when people make the PR — it should not show up on the deployed course on https://google.github.io/comprehensive-rust/ since that page is used by people who want to learn Rust. Warnings would be very disruptive there 😄 |
Yes, I am speaking the same it's should be in local development while merging PR. We have made When a PR is created regarding the change in slide.Reviewer can easily understand that it crosses number of lines as redbox popup when the slide is visited in local development. |
We already had the code for redbox, We should just need to add the trigger event when playground code lines crossed. If you are okay then we can add it in #1942 PR. |
It sounds like you're talking about JavaScript code? I'm talking about something running in a GitHub Action (a script written in Python/Rust/...). |
Ok .now, I am not about writing a script in github actions. I will check if i can do it and let you know. |
I was talking about javascript code. |
@mgeisler, hi!
An update on thresholds. There are few places, where a code block is placed inside Speaker Notes. That area has additional margins, that further decrease available space for the editable code:
86 characters seems to fit in readonly blocks regardless of their placement. |
Thanks! I missed that and used only Prerequisites:
|
I started thinking of browsing the book with playwright/selenium/etc to check for actual scrolling occurrences... |
I think our setup instructions are a little confusing (#1426), so please let me know if I've messed up and written about
Oh! I must admit that I haven't looked deeply into this myself, I was just happy to see it reformat the code blocks 🙂 I did some testing just now and I think you might have seen the effects of caching. If I run
then I do see the Rust code change after an update to |
Okay, thanks for confirming — I suggest you don't do anything here since we'll need a different tool than JavaScript here. |
That would be very interesting! I've been waiting for someone to show up with the necessary skills for something like that 😄 I would be interested in statistics that show how tall and wide each slide is. If we have tooling for this, then I could imagine having a warning on a PR that makes the page taller than a given threshold — perhaps even with a screenshot like I did manually in #1464.
Thank you for conducting this test! I tried reformatting the code in 80 columns and I think it is okay. A few of the changes can be counter-acted by simply trimming the code. As an example, |
@michael-kerscher, is this something we could detect with #2258? |
@mgeisler Yes, we can detect it with the slide evaluator if it is extended a bit. I had a look at the slides and the code examples use the ACE editor. This leverages a div element like this example -
Selenium has a nice feature to evaluate the "Displayedness" (https://w3c.github.io/webdriver/#element-displayedness) that does not directly evaluate the display attribute but if it is shown at all. Thinking about the property we want to have, it is worthwhile implementing it via this method as slides are visible in full or have some other "policy violations" already by being to big. I'm trying to extend the current mdbook-slide-evaluator to evaluate the scrollbar "displayedness". |
Nice work! We could fix the few semicolons out of place (by adjusting That should basically allow us to run this in CI? |
The style guide mentiones presentation use case for the course. That means much inconvenience while dealing with very long lines in the code snippets.
The problem was addressed earlier as it can be seen from
rustfmt.toml
configuration:This works well for read only blocks, but fails for editable ones. Due to line numbering, there is less space left for the code. My observations are that the scrolling threshold is 83 for less than 10 line long code, 82 - less than 100 and 81 - above 100. There are no snippets above 1k and I suppose there must not be in the context of the course.
The following merge request adopts max 81-character width and eliminates detected scrolling in rust code blocks.
I suppose it is a partial solution though. But further steps require a discussion.
There should be an automated format validation step.
rustfmt
can do so with rust files, but not markdown. Across the course there are examples where rust code is separated from markdown files and included like:But. Firstly, that means all the rust code should be excluded from
md
files and guides updated. Secondly, rust code contains comments that are translated. And translations can turn out to be longer than the source. And the result should also be tested. Thirdly,rustfmt
seems to ignore longuse
expressions and long strings in macro arguments - leaves them as they are without errors.Also the course has some code blocks with long shell commands and text output. Were left unchanged.
Summary questions:
use
and macros arguments that can still produce horizontal scrolling?The text was updated successfully, but these errors were encountered: