From 647ec37428caaf31a6e71e1546f1c05028917fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= <sumneko@hotmail.com> Date: Wed, 10 May 2023 17:49:47 +0800 Subject: [PATCH] support connecting by socket with `--socket=PORT` --- client/src/languageserver.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/src/languageserver.ts b/client/src/languageserver.ts index a1fb1de..11942e7 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) { -- GitLab