/lsp-types

A replacement for Microsoft.VisualStudio.LanguageServer.Protocol

Primary LanguageC#MIT LicenseMIT

lsp-types

Build

This project is a C# library for client and server Language Server Protocol (LSP) applications. It implements all the messages types in the protocol so that the developer can focus on implementing the application instead of the boilerplate code needed to convert an LSP message into C# data types. It is based on Newtonsoft.Json and StreamJsonRpc, and modeled after Microsoft.VisualStudio.LanguageServer.Protocol. Type checking is performed by the StreamJsonRpc and Newtonsoft.Json libraries for manditory or illegal values of fields of the class. Several examples are provided to demonstrate a server application.

I wrote this library because Microsoft's LSP types library is geared too closely to the LSP client for Visual Studio 2019. It is missing many major features and it is years behind the spec. However, the most important feature missing is semantic highlighting, which is a basic feature users expect in an editor extension for a language. Microsoft recommendeds the antiquated TextMate system, which is a terrible way to implement semantic highlighting for several reasons: TextMate expressions are regular expressions, which do not take into account the context-free nature of virtually all programming languages; TextMate duplicates the parsing (at a crude level) that is performed by the server, meaning that you have two places to maintain when the language changes; not all clients support TextMate; the regular expressions in TextMate are difficult to understand because they are in JSON format, and do not follow typical regular expression syntax.

Note, the current version of Microsoft.VisualStudio.LanguageServer.Protocol, v17.2.8, still does not work with Semantic Tokens and Visual Studio Code. Therefore lsp-types is still relevant.

Installation

NuGet Package is available. The version on the package reflects the version targeted, e.g., version v3.16.6 targets version 3.16 of the Specification. I currently only support 3.16, but it should be backward compatible with older implementations of the spec. Run the following command in NuGet Package Manager Console.

PM> Install-Package LanguageServerProtocol

Or, you can simply add the following to your .csproj file.

<ItemGroup>
	<PackageReference Include="LspTypes" Version="3.16.6" />
</ItemGroup>

Example

To demonstrate this library in an implementation, I provide a simple LSP server that connects to a VSCode client. See the instructions on how to run it.

The first message received by an LSP server is the Initialize Request. The server requires an implementation for the remote procedure call, which is a method in the server attributed with [JsonRpcMethod(Methods.InitializeName)]. The function of the method is to construct a InitializeResult response data type, with properties of the ServerCapabilities initialized to values the server intends to support. The capabilities field is mandatory as stated in the spec, attributed so, named with a lowercase name and attributed with the correct name.

Release notes

  • Version 3.16.6 (12 Jan 2021) -- All types brought up to date to spec 3.16, which was officially released 14 Dec 2020. This version was scraped by hand using first diffing between 1 Oct 2020 and the beginning of January. I then went through every damn type to verify that all types and properties are specified. The library is now built using Github Actions. There is still no testing of the library other than my LSP server in Antlrvsix. Issue #2 is a request to provide examples; issue #4 is a request for testing.

  • Version 3.16.5 (17 Oct 2020) -- First functional, realistic version of the library.

  • Version 0.0.4 corrects the mandatory property of field Capabilities of the class InitilizeResult.

  • Versions 0.0.1 to 0.0.3 are initial revisions to pull all the types of the LSP protocol from Antlrvsix into this library, then bring the types of the protocol up to that listed in the 3.16 spec. The library has been linked and run against Antlrvsix.

Roadmap of future releases