Skip to content

Commit 9592d0d

Browse files
authored
lsp: Exit on unexpected errors (#856)
Fixes #855
1 parent 515b333 commit 9592d0d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/lsp/LSPClient.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class LSPClient {
5454
this.ready = true;
5555
this.emit("ready");
5656

57-
// For testing blueprint language server restart
57+
// For testing language server restart
5858
// setTimeout(() => {
5959
// this.stop()
6060
// }, 5000);
@@ -85,8 +85,8 @@ export default class LSPClient {
8585

8686
async stop() {
8787
await Promise.all([
88-
this.stdin.close_async(null),
89-
this.stdout.close_async(null),
88+
this.stdin.close_async(GLib.PRIORITY_DEFAULT, null).catch(console.error),
89+
this.stdout.close_async(GLib.PRIORITY_DEFAULT, null).catch(console.error),
9090
]);
9191
// this.proc?.force_exit();
9292
this.proc.send_signal(15);
@@ -204,19 +204,28 @@ export default class LSPClient {
204204
}
205205

206206
const str = decoder_utf8.decode(uint8);
207-
return JSON.parse(str);
207+
try {
208+
return JSON.parse(str);
209+
} catch (err) {
210+
await this.stop();
211+
}
208212
}
209213

210214
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseProtocol
211215
async _read() {
212216
const headers = await this._read_headers();
213217

214-
const length = headers["Content-Length"];
218+
const length = headers?.["Content-Length"];
219+
if (!length) {
220+
return this.stop();
221+
}
222+
215223
const content = await this._read_content(length);
216-
if (content) {
217-
this._onmessage(content);
224+
if (!content) {
225+
return this.stop();
218226
}
219227

228+
this._onmessage(content);
220229
this._read().catch(console.error);
221230
}
222231

0 commit comments

Comments
 (0)