Recreate LSP Client to prevent out of sync state (#872)

This commit is contained in:
HolonProduction
2025-07-31 21:12:09 +02:00
committed by GitHub
parent bf5fcea38c
commit dfe97cb952
2 changed files with 11 additions and 11 deletions

View File

@@ -40,8 +40,7 @@ export class ClientConnectionManager {
private connectedVersion = "";
constructor(private context: vscode.ExtensionContext) {
this.client = new GDScriptLanguageClient();
this.client.events.on("status", this.on_client_status_changed.bind(this));
this.create_new_client();
setInterval(() => {
this.retry_callback();
@@ -70,6 +69,12 @@ export class ClientConnectionManager {
this.connect_to_language_server();
}
private create_new_client() {
this.client?.events?.removeAllListeners();
this.client = new GDScriptLanguageClient();
this.client.events.on("status", this.on_client_status_changed.bind(this));
}
private async connect_to_language_server() {
this.client.port = -1;
this.target = TargetLSP.EDITOR;
@@ -281,7 +286,9 @@ export class ClientConnectionManager {
}
break;
case ClientStatus.DISCONNECTED:
set_context("connectedToLSP", false);
// Disconnection is unrecoverable, since the server will not know that the reconnected client is the same.
// Create a new client with a clean state to prevent de-sync e.g. of client managed files.
this.create_new_client();
if (this.retry) {
if (this.client.port !== -1) {
this.status = ManagerStatus.INITIALIZING_LSP;

View File

@@ -93,7 +93,6 @@ export default class GDScriptLanguageClient extends LanguageClient {
public port = -1;
public lastPortTried = -1;
public sentMessages = new Map();
private initMessage: RequestMessage;
private rejected = false;
events = new EventEmitter();
@@ -201,9 +200,6 @@ export default class GDScriptLanguageClient extends LanguageClient {
}
this.sentMessages.set(message.id, message);
if (!this.initMessage && message.method === "initialize") {
this.initMessage = message;
}
// discard outgoing messages that we know aren't supported
// if (message.method === "textDocument/didSave") {
// return false;
@@ -215,6 +211,7 @@ export default class GDScriptLanguageClient extends LanguageClient {
return false;
}
if (message.method === "workspace/symbol") {
// Fixed on server side since Godot 4.5
return false;
}
@@ -356,10 +353,6 @@ export default class GDScriptLanguageClient extends LanguageClient {
const host = get_configuration("lsp.serverHost");
log.info(`connected to LSP at ${host}:${this.lastPortTried}`);
if (this.initMessage) {
this.send_request(this.initMessage.method, this.initMessage.params);
}
}
private on_disconnected() {