microsoft / microsoft/vscode-docs

[LSP] Document how to connect VSCode Language Client to already existing Language Servers

Open
#5,814 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

doc-bug extensibility
Dominant language
Markdown
Stars
6.6k
Forks
5.8k
Avg merge
11h 43m
Merged PRs (30d)
123

Description

Hello People 👋

Recently my team (@fuster92) and I had to work in implementing the validation of some files using an internal DSL. To ease the distribution among developers we decided to develop one and only Language Server following LSP guidelines. We developed it as go binary.
Then we had to connect this Server (offering the stdio interface) to the VSCode Client and we couldn't find an easy way to do it by looking at the docs: they offers a really nice overview about implementing the server, but there is little information about the client.

After several searching we found out this comment that provides a solution for connecting the client to a TCP Socket based language server.
Then after looking at the source code (And the CTRL+Click on method feature of VSCode was awesome for this) of the ServerOptions signature, we finally find out our answer, shared here for reference:

export function activate(context: ExtensionContext) {
	
       const serverOptionsAsUnixSocket = () => {
            const socket = net.connect("/tmp/my-unix-socktt");
            const result: StreamInfo = {
                writer: socket,
                reader: socket
            };
            return Promise.resolve(result);
        };

	const serverOptionsAsStdio: (() => Promise<child_process.ChildProcess>) = () => {
		const lsp = child_process.spawn("lsp", ["-stdio"]);
		return Promise.resolve(lsp);
	};

	const clientOptions: LanguageClientOptions = {
		documentSelector: [{ scheme: 'file', language: 'yaml' }],
		synchronize: {
			fileEvents: workspace.createFileSystemWatcher('**/.yaml')
		}
	};

	client = new LanguageClient(
		'client',
		'myclient',
		serverOptionsAsStdio,
		clientOptions
	);
	client.start();
}

Now, I'm not exactly sure if this is the proper way but I thought it would be nice to be documented to ease the work for developers approaching for the first time to the problem.
What do you think?

In case I can also create/help to create a PR for this.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the VS Code language-server extension guide linked in the issue, then inspect the ServerOptions signature and the activate entry point shown in the example. Document how an existing language server using stdio or a socket can be connected, and make the supported approach clear to readers implementing a client.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, typescript, vscode
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.