BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Microsoft Has Open Sourced the VS Code Language Server Protocol

Microsoft Has Open Sourced the VS Code Language Server Protocol

This item in japanese

Bookmarks

Microsoft has open sourced the protocol used by VS Code’s editor to communicate with the various language servers supported.

Visual Studio Code is an IDE from Microsoft supporting over 150 languages. To be able to carry this out, the Monaco Editor included with the tool validates the code –syntax checking, error reporting, etc – and provides Intellisense and refactoring support through language servers. Usually, there is one such server for each programing language supported. The communication between Monaco and these servers is done through the Language Server Protocol (LSP), which Microsoft has recently open sourced.

Because code validation can be a resource-expensive operation, language servers are executed in separate processes. They can be written in various languages, exchanging information with the editor through a lightweight JSON-RPC-based protocol via stdin/stdout. The protocol was inspired by the V8 debugger protocol according to Erich Gamma, the computer scientist now working on Visual Studio for Microsoft.

Similarly to HTTP, LSP includes a header section followed by a JSON-RPC content section, as shown in the following snippet:

Content-Length: ...\r\n
\r\n
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "textDocument/didOpen", 
    "params": {
        ...
    }
}

The header can contain two fields specifying the content length and type. The content is represented by a request sent to the language server or a response received from it. This section is used to send messages, notifications, and commands. Language servers can extend the features available for code validation by specifying the capabilities supported. Because it is possible to send multiple requests to different language servers at the same time, each packet includes an ID field so the editor can distinguish between replies.

The LSP decouples the editor from the language servers it uses, making it possible to use many such servers in one IDE or to reuse a language server in multiple IDEs supporting the protocol. Microsoft and other vendors already have created such servers for C++, CSS/LESS/SASS, JSON, PowerShell, Xtext, PHP and others. Eclipse Che has adopted LSP and plans to use it to add support for C/C++, C#, Go, JSON, R, TypeScript, RAML and XML. Red Hat will contribute a Java language server to Eclipse Che. There are SDKs for C#, Haxe, Java, and Node.js.

Rate this Article

Adoption
Style

BT