Debug info on frontend with #debug hash
This commit is contained in:
parent
337658a8bf
commit
404aeef235
|
@ -17,6 +17,8 @@ import { FitAddon } from "xterm-addon-fit";
|
||||||
|
|
||||||
import "xterm/css/xterm.css";
|
import "xterm/css/xterm.css";
|
||||||
|
|
||||||
|
const DEBUG = window.location.hash === "#debug";
|
||||||
|
|
||||||
interface RijuConfig {
|
interface RijuConfig {
|
||||||
id: string;
|
id: string;
|
||||||
monacoLang: string;
|
monacoLang: string;
|
||||||
|
@ -61,6 +63,9 @@ class RijuMessageReader extends AbstractMessageReader {
|
||||||
}
|
}
|
||||||
switch (message?.event) {
|
switch (message?.event) {
|
||||||
case "lspOutput":
|
case "lspOutput":
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("RECEIVE LSP:", message?.output);
|
||||||
|
}
|
||||||
this.callback!(message?.output);
|
this.callback!(message?.output);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -77,6 +82,9 @@ class RijuMessageWriter extends AbstractMessageWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
write(msg: Message): void {
|
write(msg: Message): void {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("SEND LSP:", msg);
|
||||||
|
}
|
||||||
this.socket.send(JSON.stringify({ event: "lspInput", input: msg }));
|
this.socket.send(JSON.stringify({ event: "lspInput", input: msg }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +107,13 @@ async function main() {
|
||||||
const initialRetryDelayMs = 200;
|
const initialRetryDelayMs = 200;
|
||||||
let retryDelayMs = initialRetryDelayMs;
|
let retryDelayMs = initialRetryDelayMs;
|
||||||
|
|
||||||
|
function sendMessage(message: any) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("SEND", message);
|
||||||
|
}
|
||||||
|
socket?.send(JSON.stringify(message));
|
||||||
|
}
|
||||||
|
|
||||||
function tryConnect() {
|
function tryConnect() {
|
||||||
let clientDisposable: Disposable | null = null;
|
let clientDisposable: Disposable | null = null;
|
||||||
console.log("Connecting to server...");
|
console.log("Connecting to server...");
|
||||||
|
@ -118,6 +133,9 @@ async function main() {
|
||||||
console.error("Malformed message from server:", event.data);
|
console.error("Malformed message from server:", event.data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (DEBUG && message?.event !== "lspOutput") {
|
||||||
|
console.log("RECEIVE:", message);
|
||||||
|
}
|
||||||
if (message?.event && message?.event !== "error") {
|
if (message?.event && message?.event !== "error") {
|
||||||
retryDelayMs = initialRetryDelayMs;
|
retryDelayMs = initialRetryDelayMs;
|
||||||
}
|
}
|
||||||
|
@ -190,11 +208,7 @@ async function main() {
|
||||||
let socket: WebSocket | null = null;
|
let socket: WebSocket | null = null;
|
||||||
tryConnect();
|
tryConnect();
|
||||||
|
|
||||||
term.onData(
|
term.onData((data) => sendMessage({ event: "terminalInput", input: data }));
|
||||||
(data) =>
|
|
||||||
socket &&
|
|
||||||
socket.send(JSON.stringify({ event: "terminalInput", input: data }))
|
|
||||||
);
|
|
||||||
|
|
||||||
const editor = monaco.editor.create(document.getElementById("editor")!, {
|
const editor = monaco.editor.create(document.getElementById("editor")!, {
|
||||||
minimap: { enabled: false },
|
minimap: { enabled: false },
|
||||||
|
@ -205,7 +219,7 @@ async function main() {
|
||||||
monaco.editor.setModelLanguage(editor.getModel()!, config.monacoLang);
|
monaco.editor.setModelLanguage(editor.getModel()!, config.monacoLang);
|
||||||
|
|
||||||
document.getElementById("runButton")!.addEventListener("click", () => {
|
document.getElementById("runButton")!.addEventListener("click", () => {
|
||||||
socket?.send(JSON.stringify({ event: "runCode", code: editor.getValue() }));
|
sendMessage({ event: "runCode", code: editor.getValue() });
|
||||||
});
|
});
|
||||||
|
|
||||||
MonacoServices.install(editor);
|
MonacoServices.install(editor);
|
||||||
|
|
Loading…
Reference in New Issue