-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conditionally show compile warnings when running code #1315
Conversation
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 wanted to ask if it would show all compiler output (always) or only in case of error, but I saw in the code that there is a match on the word warning
on the output. The keyword matches the behaviour.
I think it is good.
Thanks for the PR! I have a few questions and concerns.
|
Thank you for asking1 ❤️! At this point in time, the only public API that the playground guarantees will never change is All other endpoints are internal implementation details. To my recollection, no one has ever suggested working to create a stable API for the playground. 1 — This may be the first time that anyone has ever actually asked about using an endpoint before doing so! |
This piece of code may be of interest: |
:D we are prone to bikeshedding everything :P |
Responding to @ehuss above:
I chose
Good point, I haven't thought about this case. I may look into if we can adjust the logic so that
The use case I was thinking about was the various examples in Rust By Example where we expect users to play around with given code and thus having warnings would be a benefit to learning the language.
No strong reason here except it looked better visually to me to have two separate blocks of error/warning ( var show_warnings = should_warn && response.stderr.includes("warning");
// show stderr block if there is compile error or warning
if (!response.success || show_warnings) {
result_stderr_block.innerText = response.stderr;
result_stderr_block.classList.remove("hidden");
}
Is there an example of how to do this? |
Haven't had time to look into this and it doesn't look like there is much interest anyway. |
I'm interested in this feature 😄 I wrote https://github.com/google/comprehensive-rust and there we quickly noticed the lack of |
Add a stderr block. Pros: - we can make use of dbg macro in our code Cons: - there's a limitation that the compile message also shows Applies patches from rust-lang/mdBook#1315 since the original change was not adopted by rust-lang. Signed-off-by: Alx-Lai <alexabc722@gmail.com>
Add a stderr block. Pros: - we can make use of dbg macro in our code Cons: - there's a limitation that the compile message also shows Applies patches from rust-lang/mdBook#1315 since the original change was not merged by rust-lang. Signed-off-by: Alx-Lai <alexabc722@gmail.com>
Add a stderr block. Pros: - we can make use of dbg macro in our code Cons: - there's a limitation that the compile message also shows To be improved: - compile message regex may change overtime - can use websocket to replace the current approach Applies patches from rust-lang/mdBook#1315 since the original change was not merged by rust-lang. Signed-off-by: Alx-Lai <alexabc722@gmail.com>
This PR makes it so that warnings are shown if a markdown code block is labelled with
warn
e.g.This enables addressing issues like rust-lang/rust-by-example#1328.
Summary of changes:
execute
API to run code (https://play.rust-lang.org/)result
block to displaystderr
which has the warnings conditionallyHere is a demo: