Additional LSP diagnostics on frontend

This commit is contained in:
Radon Rosborough 2020-07-06 14:15:24 -06:00
parent 565379aaf3
commit fac2a9acb5
2 changed files with 43 additions and 28 deletions

View File

@ -55,21 +55,22 @@ export class Session {
this.run().catch((err) => {
this.log(`Error while setting up environment for pty`);
console.log(err);
try {
this.ws.send(JSON.stringify({ event: "terminalClear" }));
this.ws.send(
JSON.stringify({
event: "terminalOutput",
output: `Riju encountered an unexpected error: ${err}
this.send({ event: "terminalClear" });
this.send({
event: "terminalOutput",
output: `Riju encountered an unexpected error: ${err}
\rYou may want to save your code and refresh the page.
`,
})
);
} catch (err) {
//
}
});
});
}
send = (msg: any) => {
try {
this.ws.send(JSON.stringify(msg));
} catch (err) {
//
}
};
handleClientMessage = (event: string) => {
let msg: any;
try {
@ -131,11 +132,7 @@ export class Session {
this.term.pty.kill();
this.term.live = false;
}
try {
this.ws.send(JSON.stringify({ event: "terminalClear" }));
} catch (err) {
//
}
this.send({ event: "terminalClear" });
if (this.homedir == null) {
this.homedir = `/tmp/riju/${this.uuid}`;
await callPrivileged(["setup", `${this.uid}`, this.uuid], this.log);
@ -221,13 +218,7 @@ export class Session {
// Capture term in closure so that we don't keep sending output
// from the old pty even after it's been killed (see ghci).
if (term.live) {
try {
this.ws.send(
JSON.stringify({ event: "terminalOutput", output: data })
);
} catch (err) {
//
}
this.send({ event: "terminalOutput", output: data });
}
});
if (lsp && this.lsp === null) {
@ -251,17 +242,19 @@ export class Session {
const proc = spawn(lspArgs[0], lspArgs.slice(1), {
env: getEnv(this.uuid),
});
proc.on("exit", (code) => this.send({ event: "lspCrashed", code }));
proc.stderr.on("data", (data) =>
this.send({ event: "lspLog", output: data.toString("utf8") })
);
this.lsp = {
proc,
reader: new rpc.StreamMessageReader(proc.stdout),
writer: new rpc.StreamMessageWriter(proc.stdin),
};
this.lsp.reader.listen((data) => {
this.ws.send(JSON.stringify({ event: "lspOutput", output: data }));
this.send({ event: "lspOutput", output: data });
});
this.ws.send(
JSON.stringify({ event: "lspStarted", root: `/tmp/riju/${this.uuid}` })
);
this.send({ event: "lspStarted", root: `/tmp/riju/${this.uuid}` });
}
};
cleanup = async () => {

View File

@ -119,6 +119,7 @@ async function main() {
function tryConnect() {
let clientDisposable: Disposable | null = null;
let servicesDisposable: Disposable | null = null;
let lspLogBuffer = "";
console.log("Connecting to server...");
socket = new WebSocket(
(document.location.protocol === "http:" ? "ws://" : "wss://") +
@ -136,7 +137,11 @@ async function main() {
console.error("Malformed message from server:", event.data);
return;
}
if (DEBUG && message?.event !== "lspOutput") {
if (
DEBUG &&
message?.event !== "lspOutput" &&
message?.event !== "lspLog"
) {
console.log("RECEIVE:", message);
}
if (message?.event && message?.event !== "error") {
@ -198,6 +203,23 @@ async function main() {
case "lspOutput":
// Should be handled by RijuMessageReader
return;
case "lspLog":
if (typeof message.output !== "string") {
console.error("Unexpected message from server:", message);
return;
}
if (DEBUG) {
lspLogBuffer += message.output;
while (lspLogBuffer.includes("\n")) {
const idx = lspLogBuffer.indexOf("\n");
const line = lspLogBuffer.slice(0, idx);
lspLogBuffer = lspLogBuffer.slice(idx + 1);
console.log(`LSP || ${line}`);
}
}
return;
case "lspCrashed":
return;
default:
console.error("Unexpected message from server:", message);
return;