From ddfef9509b250f1a9b2432f8bb2491aba9dd01c5 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Wed, 20 Sep 2023 23:44:06 -0400 Subject: [PATCH] Random port LSP is working --- src/lsp/ClientConnectionManager.ts | 9 ++++----- src/lsp/GDScriptLanguageClient.ts | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lsp/ClientConnectionManager.ts b/src/lsp/ClientConnectionManager.ts index 23374aebb..4e0bcb843 100644 --- a/src/lsp/ClientConnectionManager.ts +++ b/src/lsp/ClientConnectionManager.ts @@ -12,11 +12,9 @@ export class ClientConnectionManager { public client: GDScriptLanguageClient = null; private reconnection_attempts = 0; - private port: number = null; private connection_status: vscode.StatusBarItem = null; - constructor(p_context: vscode.ExtensionContext) { this.context = p_context; @@ -47,8 +45,9 @@ export class ClientConnectionManager { } private connect_to_language_server() { - const start = get_configuration("lsp.runAtStartup", false) + this.client.port = -1; + const start = get_configuration("lsp.runAtStartup", false) if (start) { this.start_language_server(); } @@ -81,7 +80,7 @@ export class ClientConnectionManager { headlessFlag = "--headless"; } - this.port = await get_free_port(); + this.client.port = await get_free_port(); // TODO: find a better way to manage child processes // This way works, but it creates a terminal that the user might @@ -91,7 +90,7 @@ export class ClientConnectionManager { this.stop_language_server(); - const command = `${editorPath} --path "${projectDir}" --editor ${headlessFlag} --lsp-port ${this.port}`; + const command = `${editorPath} --path "${projectDir}" --editor ${headlessFlag} --lsp-port ${this.client.port}`; const terminal = vscode.window.createTerminal(`${TOOL_NAME}LSP`); terminal.sendText(command, true); }); diff --git a/src/lsp/GDScriptLanguageClient.ts b/src/lsp/GDScriptLanguageClient.ts index cc4127568..93ee3bca8 100644 --- a/src/lsp/GDScriptLanguageClient.ts +++ b/src/lsp/GDScriptLanguageClient.ts @@ -24,6 +24,8 @@ export default class GDScriptLanguageClient extends LanguageClient { private _initialize_request: Message = null; private message_handler: MessageHandler = null; private native_doc_manager: NativeDocumentManager = null; + + public port: number = -1; public get started() : boolean { return this._started; } public get status() : ClientStatus { return this._status; } @@ -78,8 +80,11 @@ export default class GDScriptLanguageClient extends LanguageClient { connect_to_server() { this.status = ClientStatus.PENDING; - let host = get_configuration("lsp.serverHost", "127.0.0.1"); + const host = get_configuration("lsp.serverHost", "127.0.0.1"); let port = get_configuration("lsp.serverPort", 6008); + if (this.port !== -1) { + port = this.port; + } this.io.connect_to_language_server(host, port); }