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

View File

@ -119,6 +119,7 @@ async function main() {
function tryConnect() { function tryConnect() {
let clientDisposable: Disposable | null = null; let clientDisposable: Disposable | null = null;
let servicesDisposable: Disposable | null = null; let servicesDisposable: Disposable | null = null;
let lspLogBuffer = "";
console.log("Connecting to server..."); console.log("Connecting to server...");
socket = new WebSocket( socket = new WebSocket(
(document.location.protocol === "http:" ? "ws://" : "wss://") + (document.location.protocol === "http:" ? "ws://" : "wss://") +
@ -136,7 +137,11 @@ 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") { if (
DEBUG &&
message?.event !== "lspOutput" &&
message?.event !== "lspLog"
) {
console.log("RECEIVE:", message); console.log("RECEIVE:", message);
} }
if (message?.event && message?.event !== "error") { if (message?.event && message?.event !== "error") {
@ -198,6 +203,23 @@ async function main() {
case "lspOutput": case "lspOutput":
// Should be handled by RijuMessageReader // Should be handled by RijuMessageReader
return; 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: default:
console.error("Unexpected message from server:", message); console.error("Unexpected message from server:", message);
return; return;