@codemirror/lsp-client

Hi all. I’ve published my implementation of a language server protocol client for CodeMirror, @codemirror/lsp-client. Its development was kindly sponsored by zoo.dev.

The package, as it stands, supports autocompletion, hover tooltips, signature hints, go-to-definition, symbol rename, reformatting, and finding references for a symbol. If you need support for another aspect of the LSP protocol, and would be willing to sponsor the work of adding it, contact me.

The package is set up to make it relatively easy to make custom requests to the language server, allowing you to use custom protocol extensions or implement things the package doesn’t support yet in client code.

The main points on which this differs from existing implementations are…

  • It tries to be general enough to handle multi-file scenarios and custom code that communicates with the server.

  • It is very careful about asynchronicity issues (where state changes during requests) and tries to, where it makes sense and is safe, reinterpret server responses to apply to the current version of the document, rather than the one that the server knows about, by mapping positions.

  • It uses core CodeMirror tooltips and panels for the UI parts, again helping keeping everything coherent even when the document is changed while the UI elements are active.

The package hasn’t seen a lot of use yet, except my own tests against a TypeScript server and a custom test stub LSP server, so I’m sure there are issues still, as well as unexpected server behaviors that other language servers might show. If you run into problems, please comment here or file and issue.

6 Likes

bloody brilliant! thanks to zoo.dev for the sponsor :slight_smile: