Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect external language server to VSCode extension

I want to implement a VSCode extension that uses the Language Server Protocol, but I want the server component to be on an actual server (in the cloud), and not a part of the VSCode extension.

Can I set the client extension to connect to a server via websockets or HTTP?

like image 289
Ido Avatar asked Sep 14 '25 02:09

Ido


1 Answers

Multiple ServerOptions are supported when you initialize a LanguageClient according to the signature of ServerOptions. enter image description here

you can use the StreamInfo if you want to use a real remote server as your language server. Here is a sample code to connect to your server via WebSocket and initialize a LanguageClient.

const connection = connectToServer(hostname, path);
const client = new LanguageClient(
    "docfxLanguageServer",
    "Docfx Language Server",
    () => Promise.resolve<StreamInfo>({
        reader: connection,
        writer: connection,
    }),
    {});

private connectToServer(hostname: string, path: string): Duplex {
    const ws = new WebSocket(`ws://${hostname}/${path}`);
    return WebSocket.createWebSocketStream(ws);
}
like image 73
Jiayin Pei Avatar answered Sep 16 '25 09:09

Jiayin Pei