Understanding Language Server Protocol - autocomplete, formatting - Adrian Hesketh

Learn about the Language Server Protocol (LSP), a standard for implementing language servers and clients, featuring auto-completion, formatting, and diagnostics, with a focus on its structure, functionality, and usage.

Key takeaways
  • The language server protocol (LSP) is a standard for implementing language servers and clients, which allows for features like auto-completion, formatting, and diagnostics.
  • The protocol uses JSON RPC for communication and allows for both requests and notifications.
  • The LSP has three major parts: initialization, notification, and method handling.
  • Initialization involves sending an initialized notification to the language server.
  • Notification involves sending notifications to the language server, such as when the user types or makes changes to the document.
  • Method handling involves sending requests to the language server for specific actions, such as auto-completion or formatting.
  • The LSP uses a multiplexer to handle incoming and outgoing messages, which can be implemented in Go using the net.rpc package.
  • The protocol defines several methods and notifications, including textDocument/completion, textDocument/formatting, and textDocument/diagnostics.
  • The language server should be able to handle partial updates and return diagnostic results.
  • The LSP uses a structured error for errors, which allows for easier error handling.
  • The protocol also defines a way to handle concurrency and synchronization between the language server and the client.
  • The LSP is extensible and allows for custom extensions and plugins.
  • The protocol is widely used in many editors and IDEs, including Visual Studio Code, Neovim, and Jetbrains.