Catch more errors
This commit is contained in:
parent
d3ab5d6336
commit
c9af422461
120
backend/api.js
120
backend/api.js
|
@ -417,69 +417,81 @@ export class Session {
|
||||||
};
|
};
|
||||||
|
|
||||||
stopLSP = async () => {
|
stopLSP = async () => {
|
||||||
if (this.lsp) {
|
try {
|
||||||
this.lsp.stopping = true;
|
if (this.lsp) {
|
||||||
this.lsp.proc.kill();
|
this.lsp.stopping = true;
|
||||||
this.lsp = null;
|
this.lsp.proc.kill();
|
||||||
|
this.lsp = null;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logError(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
startLSP = async () => {
|
startLSP = async () => {
|
||||||
if (this.config.lsp) {
|
try {
|
||||||
await this.stopLSP();
|
if (this.config.lsp) {
|
||||||
if (this.config.lsp.setup) {
|
await this.stopLSP();
|
||||||
await this.run(this.privilegedExec(this.config.lsp.setup));
|
if (this.config.lsp.setup) {
|
||||||
|
await this.run(this.privilegedExec(this.config.lsp.setup));
|
||||||
|
}
|
||||||
|
const lspArgs = this.privilegedExec(this.config.lsp.start);
|
||||||
|
const lspProc = spawn(lspArgs[0], lspArgs.slice(1));
|
||||||
|
const lsp = {
|
||||||
|
proc: lspProc,
|
||||||
|
reader: new rpc.StreamMessageReader(lspProc.stdout),
|
||||||
|
writer: new rpc.StreamMessageWriter(lspProc.stdin),
|
||||||
|
live: true,
|
||||||
|
stopping: false,
|
||||||
|
};
|
||||||
|
this.lsp = lsp;
|
||||||
|
this.lsp.reader.listen((data) => {
|
||||||
|
this.send({ event: "lspOutput", output: data });
|
||||||
|
});
|
||||||
|
lspProc.stderr.on("data", (data) => {
|
||||||
|
if (lsp.live) {
|
||||||
|
this.send({
|
||||||
|
event: "serviceLog",
|
||||||
|
service: "lsp",
|
||||||
|
output: data.toString("utf8"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
lspProc.on("close", (code, signal) => {
|
||||||
|
if (lsp.stopping) {
|
||||||
|
this.send({
|
||||||
|
event: "lspStopped",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.send({
|
||||||
|
event: "serviceFailed",
|
||||||
|
service: "lsp",
|
||||||
|
error: `Exited with status ${signal || code}`,
|
||||||
|
code: signal || code,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
lspProc.on("error", (err) =>
|
||||||
|
this.send({ event: "serviceFailed", service: "lsp", error: `${err}` })
|
||||||
|
);
|
||||||
|
this.send({ event: "lspStarted", root: this.homedir });
|
||||||
}
|
}
|
||||||
const lspArgs = this.privilegedExec(this.config.lsp.start);
|
} catch (err) {
|
||||||
const lspProc = spawn(lspArgs[0], lspArgs.slice(1));
|
logError(err);
|
||||||
const lsp = {
|
|
||||||
proc: lspProc,
|
|
||||||
reader: new rpc.StreamMessageReader(lspProc.stdout),
|
|
||||||
writer: new rpc.StreamMessageWriter(lspProc.stdin),
|
|
||||||
live: true,
|
|
||||||
stopping: false,
|
|
||||||
};
|
|
||||||
this.lsp = lsp;
|
|
||||||
this.lsp.reader.listen((data) => {
|
|
||||||
this.send({ event: "lspOutput", output: data });
|
|
||||||
});
|
|
||||||
lspProc.stderr.on("data", (data) => {
|
|
||||||
if (lsp.live) {
|
|
||||||
this.send({
|
|
||||||
event: "serviceLog",
|
|
||||||
service: "lsp",
|
|
||||||
output: data.toString("utf8"),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
lspProc.on("close", (code, signal) => {
|
|
||||||
if (lsp.stopping) {
|
|
||||||
this.send({
|
|
||||||
event: "lspStopped",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.send({
|
|
||||||
event: "serviceFailed",
|
|
||||||
service: "lsp",
|
|
||||||
error: `Exited with status ${signal || code}`,
|
|
||||||
code: signal || code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
lspProc.on("error", (err) =>
|
|
||||||
this.send({ event: "serviceFailed", service: "lsp", error: `${err}` })
|
|
||||||
);
|
|
||||||
this.send({ event: "lspStarted", root: this.homedir });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ensure = async (cmd) => {
|
ensure = async (cmd) => {
|
||||||
const code = (
|
try {
|
||||||
await this.run(this.privilegedExec(cmd), {
|
const code = (
|
||||||
check: false,
|
await this.run(this.privilegedExec(cmd), {
|
||||||
})
|
check: false,
|
||||||
).code;
|
})
|
||||||
this.send({ event: "ensured", code });
|
).code;
|
||||||
|
this.send({ event: "ensured", code });
|
||||||
|
} catch (err) {
|
||||||
|
logError(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
teardown = async () => {
|
teardown = async () => {
|
||||||
|
|
Loading…
Reference in New Issue