Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/lsp/LSPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class LSPClient {
this.ready = true;
this.emit("ready");

// For testing blueprint language server restart
// For testing language server restart
// setTimeout(() => {
// this.stop()
// }, 5000);
Expand Down Expand Up @@ -85,8 +85,8 @@ export default class LSPClient {

async stop() {
await Promise.all([
this.stdin.close_async(null),
this.stdout.close_async(null),
this.stdin.close_async(GLib.PRIORITY_DEFAULT, null).catch(console.error),
this.stdout.close_async(GLib.PRIORITY_DEFAULT, null).catch(console.error),
]);
// this.proc?.force_exit();
this.proc.send_signal(15);
Expand Down Expand Up @@ -204,19 +204,28 @@ export default class LSPClient {
}

const str = decoder_utf8.decode(uint8);
return JSON.parse(str);
try {
return JSON.parse(str);
} catch (err) {
await this.stop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopping the LSP on an error is a good idea, but not re-throwing the error could potentially make debugging harder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing that the input isn't valid JSON isn't particularly helpful, so one has to investigate anyway.
Working with LSP servers is rather cumbersome 😞

}
}

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

const length = headers["Content-Length"];
const length = headers?.["Content-Length"];
if (!length) {
return this.stop();
}

const content = await this._read_content(length);
if (content) {
this._onmessage(content);
if (!content) {
return this.stop();
}

this._onmessage(content);
this._read().catch(console.error);
}

Expand Down