diff --git a/client/src/languageserver.ts b/client/src/languageserver.ts index a1fb1ded8d138c746c33ce95410bc444474e5c58..11942e78dab245e649211573a771d13fadb4cd6d 100644 --- a/client/src/languageserver.ts +++ b/client/src/languageserver.ts @@ -18,6 +18,7 @@ import { DocumentSelector, LSPAny, ExecuteCommandRequest, + TransportKind, } from 'vscode-languageclient/node'; export let defaultClient: LuaClient | null; @@ -106,8 +107,14 @@ class LuaClient { if (!Array.isArray(commandParam)) throw new Error("Lua.misc.parameters must be an Array!"); + const port = this.getPort(commandParam); + const serverOptions: ServerOptions = { command: command, + transport: port ? { + kind: TransportKind.socket, + port: port, + } : undefined, args: commandParam, }; @@ -177,6 +184,23 @@ class LuaClient { return command; } + // Generated by Copilot + private getPort(commandParam: string[]): number | undefined { + // "--socket=xxxx" or "--socket xxxx" + const portIndex = commandParam.findIndex((value) => { + return value.startsWith("--socket"); + }); + if (portIndex === -1) { + return undefined; + }; + const port = commandParam[portIndex].split("=")[1] + || commandParam[portIndex + 1]; + if (!port) { + return undefined; + }; + return Number(port); + } + async stop() { this.client.stop(); for (const disposable of this.disposables) {