mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-19 22:19:29 +02:00
Add "Execution: Add stderr block" again (#2503)
Reverts google/comprehensive-rust#2479, which is a revert of #2397. I think the problem was not related to @Alx-Lai's change, the [Playground was slow](https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/playground.20incident.202024-12-03) for everyone.
This commit is contained in:
parent
be476391f2
commit
5f2248bb92
@ -110,10 +110,17 @@ function playground_text(playground, hidden = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run_rust_code(code_block) {
|
function run_rust_code(code_block) {
|
||||||
var result_block = code_block.querySelector(".result");
|
var result_stderr_block = code_block.querySelector(".result.stderr");
|
||||||
|
if (!result_stderr_block) {
|
||||||
|
result_stderr_block = document.createElement('code');
|
||||||
|
result_stderr_block.className = 'result stderr hljs nohighlight hidden';
|
||||||
|
|
||||||
|
code_block.append(result_stderr_block);
|
||||||
|
}
|
||||||
|
var result_block = code_block.querySelector(".result.stdout");
|
||||||
if (!result_block) {
|
if (!result_block) {
|
||||||
result_block = document.createElement('code');
|
result_block = document.createElement('code');
|
||||||
result_block.className = 'result hljs language-bash';
|
result_block.className = 'result stdout hljs nohighlight';
|
||||||
|
|
||||||
code_block.append(result_block);
|
code_block.append(result_block);
|
||||||
}
|
}
|
||||||
@ -127,10 +134,13 @@ function playground_text(playground, hidden = true) {
|
|||||||
edition = "2021";
|
edition = "2021";
|
||||||
}
|
}
|
||||||
var params = {
|
var params = {
|
||||||
version: "stable",
|
backtrace: true,
|
||||||
optimize: "0",
|
channel: "stable",
|
||||||
code: text,
|
code: text,
|
||||||
edition: edition
|
edition: edition,
|
||||||
|
mode: "debug",
|
||||||
|
tests: false,
|
||||||
|
crateType: "bin",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (text.indexOf("#![feature") !== -1) {
|
if (text.indexOf("#![feature") !== -1) {
|
||||||
@ -138,10 +148,13 @@ function playground_text(playground, hidden = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result_block.innerText = "Running...";
|
result_block.innerText = "Running...";
|
||||||
|
// hide stderr block while running
|
||||||
|
result_stderr_block.innerText = "";
|
||||||
|
result_stderr_block.classList.add("hidden");
|
||||||
|
|
||||||
const playgroundModified = isPlaygroundModified(code_block);
|
const playgroundModified = isPlaygroundModified(code_block);
|
||||||
const startTime = window.performance.now();
|
const startTime = window.performance.now();
|
||||||
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
|
fetch_with_timeout("https://play.rust-lang.org/execute", {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': "application/json",
|
'Content-Type': "application/json",
|
||||||
},
|
},
|
||||||
@ -158,13 +171,26 @@ function playground_text(playground, hidden = true) {
|
|||||||
"latency": (endTime - startTime) / 1000,
|
"latency": (endTime - startTime) / 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.result.trim() === '') {
|
if (response.stdout.trim() === '') {
|
||||||
result_block.innerText = "No output";
|
result_block.innerText = "No output";
|
||||||
result_block.classList.add("result-no-output");
|
result_block.classList.add("result-no-output");
|
||||||
} else {
|
} else {
|
||||||
result_block.innerText = response.result;
|
result_block.innerText = response.stdout;
|
||||||
result_block.classList.remove("result-no-output");
|
result_block.classList.remove("result-no-output");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trim compile message
|
||||||
|
// ====================
|
||||||
|
// Compiling playground v0.0.1 (/playground)
|
||||||
|
// Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.60s
|
||||||
|
// Running `target/debug/playground`
|
||||||
|
// ====================
|
||||||
|
const compileMsgRegex = /^\s+Compiling(.+)\s+Finished(.+)\s+Running(.+)\n/;
|
||||||
|
response.stderr = response.stderr.replace(compileMsgRegex, "");
|
||||||
|
if (response.stderr.trim() !== '') {
|
||||||
|
result_stderr_block.classList.remove("hidden");
|
||||||
|
result_stderr_block.innerText = response.stderr;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const endTime = window.performance.now();
|
const endTime = window.performance.now();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user