Skip to content

Commit 647ec37

Browse files
committed
support connecting by socket with --socket=PORT
1 parent 249fd62 commit 647ec37

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

client/src/languageserver.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
DocumentSelector,
1919
LSPAny,
2020
ExecuteCommandRequest,
21+
TransportKind,
2122
} from 'vscode-languageclient/node';
2223

2324
export let defaultClient: LuaClient | null;
@@ -106,8 +107,14 @@ class LuaClient {
106107

107108
if (!Array.isArray(commandParam)) throw new Error("Lua.misc.parameters must be an Array!");
108109

110+
const port = this.getPort(commandParam);
111+
109112
const serverOptions: ServerOptions = {
110113
command: command,
114+
transport: port ? {
115+
kind: TransportKind.socket,
116+
port: port,
117+
} : undefined,
111118
args: commandParam,
112119
};
113120

@@ -177,6 +184,23 @@ class LuaClient {
177184
return command;
178185
}
179186

187+
// Generated by Copilot
188+
private getPort(commandParam: string[]): number | undefined {
189+
// "--socket=xxxx" or "--socket xxxx"
190+
const portIndex = commandParam.findIndex((value) => {
191+
return value.startsWith("--socket");
192+
});
193+
if (portIndex === -1) {
194+
return undefined;
195+
};
196+
const port = commandParam[portIndex].split("=")[1]
197+
|| commandParam[portIndex + 1];
198+
if (!port) {
199+
return undefined;
200+
};
201+
return Number(port);
202+
}
203+
180204
async stop() {
181205
this.client.stop();
182206
for (const disposable of this.disposables) {

0 commit comments

Comments
 (0)