Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is It possible that vs code LSP client can connect with server use tcp or websocket? #662

Closed
hasegetc opened this issue Aug 21, 2020 · 5 comments
Labels
help wanted Issues identified as good community contribution opportunities

Comments

@hasegetc
Copy link

@rcjsuen
Copy link
Contributor

rcjsuen commented Aug 21, 2020

@hasegetc The documents you are linking to are for Visual Studio but I assume you are talking about Visual Studio Code.

export enum TransportKind {
stdio,
ipc,
pipe,
socket
}

You should be able to use TransportKind.socket to tell the LSP client in VS Code to connect using TCP.

@hasegetc
Copy link
Author

@rcjsuen thank you very much for you reply. but just in the vscode-languageserver-node/client/src/node/main.ts write, there just transport.port in the source code, I cant find where is transport.ip. is TransportKind.socket just for IPC connect? or how can I use ip and port in TransportKind.socket to connect to remote lsp server?

@dbaeumer
Copy link
Member

I have never tested connecting to a server using WebSockets. From my experiences in VS Code extension host this needs some special code since you need to implement some special hand shaking (see https://github.com/microsoft/vscode/blob/645f5850141b13b3d194e389eabf83eacc785bb5/src/vs/base/parts/ipc/node/ipc.net.ts#L79-L257)

I am open for a PR that adds this.

@dbaeumer dbaeumer added this to the Backlog milestone Aug 21, 2020
@dbaeumer dbaeumer added the help wanted Issues identified as good community contribution opportunities label Aug 21, 2020
@hasegetc
Copy link
Author

  • @dbaeumer thank you very much
  • I find the answer by you :How do I use tcp/socket? language-server-protocol#604. "What needs to be understood is that for connection timing issues the server is actually a client and the client is the server in terms of opening the ports."
  • does you mean that the vs code lsp extention is the tcp server, and the lsp server is the tcp client, the lsp server use the lsp client's ip + port to establish the connection?

@hasegetc
Copy link
Author

hasegetc commented Aug 22, 2020

I find the solution


export function activate(context: ExtensionContext) {
	let connectionInfo = {
		port: 5007,
		host: "192.168.0.152"
    };

	// The server is implemented in node
	let serverModule = context.asAbsolutePath(
		path.join('server', 'out', 'server.js')
	);
	// The debug options for the server
	// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
	let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };

	// If the extension is launched in debug mode then the debug server options are used
	// Otherwise the run options are used
	// let serverOptions: ServerOptions = {
	// 	run: { module: serverModule, transport: TransportKind.socket },
	// 	debug: {
	// 		module: serverModule,
	// 		transport: TransportKind.socket,
	// 		options: debugOptions
	// 	}
	// };

	let serverOptions = () => {
        // Connect to language server via socket
        let socket = net.connect(connectionInfo);
        let result: StreamInfo = {
            writer: socket,
            reader: socket
        };
        return Promise.resolve(result);
    };

	// Options to control the language client
	let clientOptions: LanguageClientOptions = {
		// Register the server for plain text documents
		documentSelector: [{ scheme: 'file', language: 'plaintext' }],
		synchronize: {
            fileEvents: workspace.createFileSystemWatcher('**/*.*')
        }
	};

	// Create the language client and start the client.
	client = new LanguageClient(
		'languageServerExample',
		'Language Server Example',
		serverOptions,
		clientOptions
	);

	// Start the client. This will also launch the server
	client.start();
}

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 6, 2020
@dbaeumer dbaeumer removed this from the Backlog milestone Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

3 participants